-
-
Notifications
You must be signed in to change notification settings - Fork 670
Catch duplicate instance and static members #797
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
"'{0}' must be a power of two.": 223, | ||
"Expression is unsafe.": 224, | ||
"Expression is never 'null'.": 225, | ||
"Duplicate instance member '{0}'.": 231, | ||
"Duplicate static member '{0}'.": 232, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have so far preferred to use TS errors if these are available, and only resort to use custom errors where there's no alternative. In this case, I think that "Duplicate identifier", which TS already has, transports the necessary information already - or doesn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MaxGraey was the one who mentioned If we use If you'd rather use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding the "why" I'd say that a better solution for this particular concern would be to implement error chains eventually, indicating the conflicting declaration in addition to the actual error. Like, emitting a "duplicate identifier" here isn't so different from emitting it elsewhere, for example if there are multiple functions of the same name. That also doesn't give us detailed information, so using the error here as well is consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So would you rather we revert this PR (and just fix the bug in the duplicate error check) or extend this PR to cover all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just suggesting to revert the custom AS errors, and use the existing duplicate identifier error instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is fixing the bug that is listed in the connected issue (#793) The change from So is there an agreement between you and @MaxGraey as to what you want the error to be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically only that line (and the test cases possibly) are needed to fix the assertion error, but we added the other messages on advice from @MaxGraey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dcodeIO TS inherit JS behaviour which call everything as identifier (class/instance member, fields in object and simple identifiers of variables and constants). I guess will be great have more precise diagnostic for such entities. Probably we could do soming like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to align with TS where possible to provide a unified developer experience. Might also have implications on tooling that expect those exact TS error numbers for some reason. Ideally, we'd use TS errors like "Duplicate Identifier" but also implement error chains to highlight the conflicting identifier. Afaik TS has something like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, error chains could concrete errors. Nice |
||
|
||
"Unterminated string literal.": 1002, | ||
"Identifier expected.": 1003, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"asc_flags": [ | ||
"--runtime none" | ||
], | ||
"stderr": [ | ||
"AS231: Duplicate instance member 'field'.", | ||
"AS232: Duplicate static member 'static_field'.", | ||
"EOF" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ERROR("SOF"); | ||
|
||
class FailureTest { | ||
field: i64; | ||
field: u32; | ||
|
||
static static_field: string; | ||
static static_field: i32; | ||
} | ||
|
||
const fail = new FailureTest(); | ||
|
||
ERROR("EOF"); |
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.
nit: if expression and it's body contain in same line braces is unnecessary
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.
I assumed since it didn't fail a lint that it wasn't enforced either way, if there is a preference would it be reasonable to add the check into a lint rule on a new PR?