Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor typechecking for use functions with UsedAs<T> #325

Open
dphfox opened this issue Apr 16, 2024 · 0 comments
Open

Poor typechecking for use functions with UsedAs<T> #325

dphfox opened this issue Apr 16, 2024 · 0 comments
Labels
broken Something isn't right not ready - blocked Waiting on other work to be done

Comments

@dphfox
Copy link
Owner

dphfox commented Apr 16, 2024

<T>(T | {T}) -> T creates a free type when called.

type Use = <T>(UsedAs<T>) -> T
type UsedAs<T> = T | {T} -- approximation of the real type in Fusion

-- only care about the static types, this doesn't need to run
local use: Use = nil :: any
local input: UsedAs<number> = nil :: any

 -- `output` inferred to be a free type, rather than the expected `number`
local output = use(input)

This relates to the currently-suboptimal type inference for use functions.

The new solver doesn't entirely solve for this, though it does give a "yes, technically" kind of answer.

It currently matches T to number | {number} and then substitutes it to get (number | {number} | {number | {number}}) -> number | {number}

I'll make a ticket for it though. We should be able to get it to do some structural matching to try to get the smallest possible type for the instantiation.

(and if we couldn't, that'd actually be a really strong motivator for adding explicit instantiation syntax for all those turbofish-heads out there.)

@dphfox dphfox added broken Something isn't right not ready - blocked Waiting on other work to be done labels Apr 16, 2024
@dphfox dphfox moved this to Prospective in Fusion 0.3 Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken Something isn't right not ready - blocked Waiting on other work to be done
Projects
Status: Prospective
Development

No branches or pull requests

1 participant