File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -368,7 +368,13 @@ bool Compiler::Instruction()
368
368
case Token::Type::If:
369
369
{
370
370
Token ifStart = *CurrentToken ();
371
+ Token elseStart;
371
372
currentToken++;
373
+ if (!CurrentToken ())
374
+ {
375
+ ErrorAt (*PreviousToken (), " Unterminated if statement" );
376
+ break ;
377
+ }
372
378
uint16_t ifOffset = EmitJump (OpCode::JumpIfFalse);
373
379
uint16_t elseOffset = 0 ;
374
380
@@ -395,13 +401,19 @@ bool Compiler::Instruction()
395
401
}
396
402
else
397
403
{
404
+ elseStart = *CurrentToken ();
398
405
elseOffset = EmitJump (OpCode::Jump);
399
406
PatchJump (ifOffset);
400
407
ifPatched = true ;
401
408
currentToken++;
402
409
}
403
410
}
404
411
}
412
+ if (!CurrentToken ())
413
+ {
414
+ ErrorAt ((ifPatched ? elseStart : ifStart), (ifPatched ? " Unterminated else statement" : " Unterminated if statement" ));
415
+ break ;
416
+ }
405
417
PatchJump (ifPatched ? elseOffset : ifOffset);
406
418
break ;
407
419
}
You can’t perform that action at this time.
0 commit comments