Fixes #2589: type redeclarations cause spurious warnings#2591
Conversation
This addresses the problem by refusing to re-bind the explit type for a name once one type was already present. This means it changes the logic from "last type declaration wins" to "first type declaration wins". The error about redeclaring the type is still being reported but the type does not change, which changes the errors given, producing less surprising results. Test plan: added a new test case to unit/semanal. Without the change, there's spurious errors about names not conforming to the type defined last. With the change, only the "Name already defined" errors remain.
|
Looks good -- thanks for the fix! |
|
This change prevents an "incompatible types in assignment" error from being generated on lines with a "Name already defined" errors. E.g.: now gives only the error: whereas previously it would also give: I think we want that error, so this should perhaps be fixed in a slightly different place. |
|
In the previous case, it was the first line that would emit the error: This is confusing and the point of this pull request. With the fix, there is an error being emitted only on line 2: Removing the second type comment will emit your original error: In other words, no information is lost but there's no confusing error being emitted on a line that preceeds the problem. |
|
Oh, you're right! Sorry, I didn't read the output carefully enough. This is strictly an improvement, then. Thanks! 👍 |
This addresses the problem by refusing to re-bind the explicit type for a name once one type was already present. This means it changes the logic from "last type declaration wins" to "first type declaration wins". The error about redeclaring the type is still being reported but the type does not change, which changes the errors given, producing less surprising results.
Test plan: added a new test case to
unit/semanal. Without the change, there's spurious errors about names not conforming to the type defined last. With the change, only the "Name already defined" errors remain.