Generate useful error for TA input "s"

see #15
This commit is contained in:
Arne Keller 2021-07-19 11:06:56 +02:00
parent 0285305f13
commit 5e6cb6ca4c
2 changed files with 13 additions and 1 deletions

View File

@ -172,7 +172,9 @@ public class TypeAssumptionParser {
if (t.getType() == TokenType.COLON) { if (t.getType() == TokenType.COLON) {
return new ParserResult<>(new ExpectingTypeDef(alreadyParsed, var)); return new ParserResult<>(new ExpectingTypeDef(alreadyParsed, var));
} else { } else {
return new ParserResult<>(ParseError.unexpectedToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR)); return new ParserResult<>(ParseError
.unexpectedToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR)
.expectedType(TokenType.COLON));
} }
} }
} }

View File

@ -349,6 +349,16 @@ class TypeAssumptionParserTest {
assertEquals(Token.TokenType.EOF, e.getCause().get().getType()); assertEquals(Token.TokenType.EOF, e.getCause().get().getType());
} }
@Test
void errorCase3() {
ParseError e = parse("s");
assertEquals(ParseError
.unexpectedToken(new Token(Token.TokenType.EOF, "", "s", 1),
ParseError.ErrorType.TYPE_ASSUMPTION_ERROR)
.expectedType(Token.TokenType.COLON),
e);
}
static ParseError parse(String input) { static ParseError parse(String input) {
return new TypeAssumptionParser().parse(input).unwrapError(); return new TypeAssumptionParser().parse(input).unwrapError();
} }