forked from ponylang/ponyc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compiler crash in alternate name suggestion logic (issue ponylang…
…#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.
- Loading branch information
1 parent
26623eb
commit 41c74b9
Showing
2 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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,68 @@ | ||
#include <gtest/gtest.h> | ||
#include <platform.h> | ||
|
||
#include "util.h" | ||
|
||
#define TEST_ERRORS(src, err1) \ | ||
{ const char* errs[] = {err1, NULL}; \ | ||
DO(test_expected_errors(src, "ir", errs)); } | ||
|
||
class SuggestAltNameTest : public PassTest | ||
{}; | ||
|
||
TEST_F(SuggestAltNameTest, SuggestAltName_Private) | ||
{ | ||
const char* src = | ||
"actor Main\n" | ||
" var _aStr: String = \"help\"\n" | ||
|
||
" new create(env: Env) =>\n" | ||
" _aStr = xx()\n" | ||
|
||
" fun xx(): String =>\n" | ||
" aStr // Undefined suggest _aStr\n"; | ||
|
||
TEST_ERRORS(src, | ||
"can't find declaration of 'aStr', did you mean '_aStr'?"); | ||
} | ||
|
||
TEST_F(SuggestAltNameTest, SuggestAltName_DifferentCaseVariable) | ||
{ | ||
const char* src = | ||
"actor Main\n" | ||
" var aStr: String = \"help\"\n" | ||
|
||
" new create(env: Env) =>\n" | ||
" aStr = xx()\n" | ||
|
||
" fun xx(): String =>\n" | ||
" astr // Undefined, suggest aStr\n"; | ||
|
||
TEST_ERRORS(src, | ||
"can't find declaration of 'astr', did you mean 'aStr'?"); | ||
} | ||
|
||
TEST_F(SuggestAltNameTest, SuggestAltName_DifferentCaseMethod) | ||
{ | ||
const char* src = | ||
"actor Main\n" | ||
" new create(env: Env) =>\n" | ||
" doit() // Undefined, suggest doIt\n" | ||
|
||
" fun doIt() =>\n" | ||
" None\n"; | ||
|
||
TEST_ERRORS(src, | ||
"can't find declaration of 'doit', did you mean 'doIt'?"); | ||
} | ||
|
||
TEST_F(SuggestAltNameTest, SuggestAltName_NothingToSuggest) | ||
{ | ||
const char* src = | ||
"actor Main\n" | ||
" new create(env: Env) =>\n" | ||
" doIt() // Undefined, nothing to suggest\n"; | ||
|
||
TEST_ERRORS(src, | ||
"can't find declaration of 'doIt'"); | ||
} |