Skip to content

Commit 33c34b5

Browse files
authored
Merge pull request #2905 from fernewelten/NC_LineNumbers
New compiler: Report the correct line number when encountering an unknown symbol
2 parents a83841a + 24ef2b2 commit 33c34b5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Compiler/script2/cs_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,6 +6842,7 @@ void AGS::Parser::ParseAssignmentOrExpression()
68426842
!_sym.IsPredefined(next_sym) &&
68436843
_sym.kNoSrcLocation == _sym.GetDeclared(next_sym))
68446844
{
6845+
SkipNextSymbol(_src, next_sym);
68456846
UserError("Identifier '%s' is undeclared (did you mis-spell it?)", _sym.GetName(next_sym).c_str());
68466847
}
68476848
if (expression.Length() == 0u)

Compiler/test2/cc_parser_test_2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,16 @@ TEST_F(Compile2, NullAsStringArgument) {
12081208
TEST_F(Compile2, Unexpected_Undefined) {
12091209

12101210
// Should complain about "undeclared" function instead of "unexpected" symbol
1211+
// Undefined symbol should be reported for line #9, not earlier
12111212

12121213
std::string inpl = R"%&/(
12131214
void game_start()
12141215
{
1216+
int i;
1217+
1218+
1219+
1220+
12151221
func(null);
12161222
}
12171223
)%&/";
@@ -1221,4 +1227,5 @@ TEST_F(Compile2, Unexpected_Undefined) {
12211227

12221228
ASSERT_STRNE("Ok", mh.HasError() ? err_msg.c_str() : "Ok");
12231229
EXPECT_NE(std::string::npos, err_msg.find("ndeclared"));
1230+
ASSERT_EQ(9, mh.GetError().Lineno);
12241231
}

0 commit comments

Comments
 (0)