-
-
Notifications
You must be signed in to change notification settings - Fork 427
Fix spurious 'can't reuse name' errors when a multi-file package has a syntax error #5147
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
Open
pmetras
wants to merge
6
commits into
ponylang:main
Choose a base branch
from
pmetras:issue-4160/spurious-error-message-generation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f01b98
Broken multi-files package reports illegal name reuses
pmetras 366324d
Merge branch 'ponylang:main' into issue-4160/spurious-error-message-g…
pmetras 0d52bf0
Add release notes
pmetras 59933c0
Better release message
pmetras 29bbb38
Removed lines wrap
pmetras 984e1a1
Merge branch 'main' into issue-4160/spurious-error-message-generation
pmetras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ## Fix spurious 'can't reuse name' errors when a multi-file package has a syntax error | ||
|
|
||
| When a package contained multiple `.pony` files and one of them had a syntax error, the compiler would produce spurious `can't reuse name` errors for unrelated valid code in the other files. This was most visible when a valid file reused a loop variable name across consecutive `for` loops — a perfectly legal pattern that the compiler would incorrectly flag. | ||
|
|
||
| The spurious errors no longer appear. You'll still see the real syntax error, but the compiler won't pile on with bogus errors from other files in the same package. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1735,3 +1735,30 @@ TEST_F(BadPonyTest, MatchTuplePatternFromAliasedTupleUnsound) | |
| "this capture is unsound", | ||
| "this capture is unsound"); | ||
| } | ||
|
|
||
| TEST_F(BadPonyTest, SpuriousErrorMessageGeneration) | ||
| { | ||
| // From issue #4160 | ||
| // A parse error in one file of a package must not produce spurious | ||
| // "can't reuse name" errors in other files of the same package that | ||
| // reuse a loop variable name across consecutive for loops. | ||
| // The fixture package has two files: bad.pony (parse error) comes before | ||
| // good.pony (valid, with consecutive "for i" loops) alphabetically. | ||
| add_package_path("pkg", PONY_TEST_LIBPONYC_DIR "/fixtures/spurious-error-message-generation"); | ||
|
Member
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. im not a fan of adding fixtures to a testing style we are trying to move away from. @jemc what are your thoughts? |
||
| const char* src = | ||
| "use \"pkg\"\n" | ||
| "actor Main\n" | ||
| " new create(env: Env) =>\n" | ||
| " for i in Range(0, 3) do\n" | ||
| " None\n" | ||
| " end\n" | ||
| " for i in Range(0, 3) do\n" | ||
| " None\n" | ||
| " end"; | ||
|
|
||
| TEST_ERRORS_2(src, | ||
| "syntax error: unexpected token = after type, interface, trait, primitive," | ||
| " class or actor definition", | ||
| "can't load package 'pkg'"); | ||
| } | ||
|
|
||
4 changes: 4 additions & 0 deletions
4
test/libponyc/fixtures/spurious-error-message-generation/bad.pony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Intentional syntax error: = instead of => | ||
| class Bad | ||
| new create() = | ||
| None |
16 changes: 16 additions & 0 deletions
16
test/libponyc/fixtures/spurious-error-message-generation/good.pony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Syntactically valid file in the same package as bad.pony. | ||
| // The loop variable 'i' is reused across consecutive for loops; before the | ||
| // fix for issue #4160, a parse error in bad.pony caused spurious | ||
| // "can't reuse name 'i'" errors here. | ||
| class Good | ||
| new create() => | ||
| let a: Array[U8] = Array[U8] | ||
| for i in a.values() do | ||
| None | ||
| end | ||
| for i in a.values() do | ||
| None | ||
| end | ||
| for i in a.values() do | ||
| None | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could use a brief comment here. Even just a pointer to the comment on the other branch below so someone reading this code path doesn't have to go hunting for why the flag is being set.