Skip to content
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

Fix compiler crash in alternate name suggestion logic (issue #2508). #2552

Merged
merged 2 commits into from Feb 28, 2018

Conversation

winksaville
Copy link
Contributor

The pony_assert(ast_id(id == TK_ID) assumes that ast_id(id)) is
always a TK_ID, but that is not the true if the first child of case_ast
is a function or behavior.

This fix checks for a TK_ID for both first and second children of
case_ast and gives up if neither is a TK_ID instead of asserting.

@winksaville
Copy link
Contributor Author

This is a possible fix for #2508.

@winksaville
Copy link
Contributor Author

The commit WIP-Fix-issue-2508-with-dbg has some debug and an test case in minimal-cases/issue-2508.

@jemc
Copy link
Member

jemc commented Feb 21, 2018

I'd like to see a regression test added for this in the compiler tests instead of the minimal-cases folder.

That is, I think we can test that the correct error is returned instead of crashing the compiler (as it currently does).

@winksaville
Copy link
Contributor Author

I don't understand, the crash is in suggest_alt_name where the compiler is assuming there was a typo and it's trying to guess what that might be. My fix removes the pony_assert, adds some additional code to improve the guess and either finds a suggestion or returns NULL.

The WIP-Fix-issue-2508-with-dbg and minimal-case/issue-2508 code was only used durning developement of the fix and I'm not sure we'd want to make any specific assumtions on what suggest_alt_name should return. If you want, I can add some version(s) of my minimal-case and test that specific suggestions are returned. But, as I said up above, maybe I just don't understand what you meant.

@jemc
Copy link
Member

jemc commented Feb 22, 2018

Sorry, I can try to be more clear.

I meant that this PR should add a test to test/libponyc/badpony.cc with the minimal case from this comment: #2508 (comment)

That test should verify that the compiler returns the correct compile error instead of crashing.

@winksaville
Copy link
Contributor Author

winksaville commented Feb 22, 2018 via email

The pony_assert(ast_id(id == TK_ID) assumes that ast_id(id)) is
always a TK_ID, but that is not the true if the first child of case_ast
is a function or behavior.

This fix checks for a TK_ID for both first and second children of
case_ast and gives up if neither is a TK_ID instead of asserting.
There are three cases tested plus a test for nothing can be suggested.
@winksaville
Copy link
Contributor Author

@jemc, I've added some tests, please take a look.

@jemc jemc changed the title Fix for issue 2508 Fix compiler crash in alternate name suggestion logic (issue #2508). Feb 28, 2018
@jemc jemc added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Feb 28, 2018
@jemc jemc merged commit 45cedba into ponylang:master Feb 28, 2018
ponylang-main added a commit that referenced this pull request Feb 28, 2018
@SeanTAllen
Copy link
Member

Awesome. Thanks @winksaville.

@winksaville winksaville deleted the Fix-issue-2508 branch March 1, 2018 19:58
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
…#2508). (ponylang#2552)

* Fix for issue 2508

The pony_assert(ast_id(id == TK_ID) assumes that ast_id(id)) is
always a TK_ID, but that is not the true if the first child of case_ast
is a function or behavior.

This fix checks for a TK_ID for both first and second children of
case_ast and gives up if neither is a TK_ID instead of asserting.

* Add tests for suggest_alt_name

There are three cases tested plus a test for nothing can be suggested.
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants