-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Type error: wrong type match #188
Comments
This is because the array literal is ambiguous: In this specific case the type signature of the I would suggest to do what Crystal does: specify the type of the empty array as In that case this would not be ambiguous:
Of course this would be a big breaking change 🚧 |
@gdotdesign Why not just force to use types of parent record type? |
The answer for this is that we don't know the parent record the beforehand. To explain what is happening here: basically the compiler "sees" records in isolation (without type definitions) like this:
and it's type is inferred to be this:
and after finding a type
it becomes this:
Which does not match any defined type. An other way to go would be to add type definition to records as This is one of the reasons why Crystal has the |
Thank you for the explanation. I (think I) understand the algorithm but from a user experience it's very tedious to play with type system and guess what's bad. If I'm made (only at this point, hopefully) to explicitly define variable/state types then I want to do it for something. It's not nice to provide the typename twice:
I know this is not easy but I believe this really needs an improvement. And since we would aim for better error messages then this could be a good step to improve the type-matching algorithm. The algorithm would be:
So, instead of treating |
Thank you for the explanation, really appreciate it 👍 You are right, we can and should make better error messages if possible, in this case it is certainly possible, I just wanted to point out that it would not solve the underlying issue. After thinking about it we can try not to resolve sub fields records to types and can just use their type signatures to match the parent record to a type, but in this case it would not work I am afraid since as you wrote an empty array resolves as I like having I suggest to keep this issue for having a nicer error message for states and properties if they are records, and make an other for the underlying issue. |
Issue
When assigning a value the compiler seems to guess a type of value and then it type-checks the value with a
state
field. This results in an error where properly defined data structure cannot be compiled.In the code below both
islands
andconnections
look the same:However, internally they are different in all (2) subfields:
Expected behaviour
Since I've defined my
state puzzle
to be a specific type (herePuzzle
) I would expect that to be a priority. Thus, type-check should continue the search.Reproduction
https://sandbox.mint-lang.com/sandboxes/tweRxXyq9aa8Rg
The text was updated successfully, but these errors were encountered: