-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Compile error when comparing sugared constructors with 'is' or 'isnt' (#2024) #2494
Conversation
Error in Windows compilation:
|
src/libponyc/pass/refer.c
Outdated
type = ast_data(ast); | ||
if(ast_id(type) != TK_PRIMITIVE) | ||
{ | ||
ast_error(opt->check.errors, ast, "comparing a non-primitive type constructor will always fail"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good error message except I think the folks who are most likely to trigger it might not realize they are doing "as" against a constructor even when they see the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed it. Hopefully it's clearer now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you.
I've left a comment on the source changes.
@@ -1334,6 +1378,8 @@ ast_result_t pass_refer(ast_t** astp, pass_opt_t* options) | |||
case TK_ERROR: r = refer_error(options, ast); break; | |||
case TK_COMPILE_ERROR: | |||
r = refer_compile_error(options, ast); break; | |||
case TK_IS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should cover TK_ISNT
as well.
When we add support for |
…#2024) An identity comparison with a new object will always be false, so this will catch mistaken 'is' comparisons without affecting legitimate uses.
Oops. Added the TK_ISNT case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge when CI passes.
CI failure is just Travis macos glitching out. Going to merge this. |
#2024
Compile error when using 'is' to compare sugared type constructors, including cases where they are embedded in tuples or seqs.
I didn't include array literals in these changes, but I think those could also be an issue. For example,
[1; 2; 3] is [1; 2; 3]
is false, which could cause the same kind of confusion.