mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Reject duplicate quantified type variables
This commit is contained in:
parent
df218d8be8
commit
394b5a3d23
@ -441,7 +441,12 @@ public class TypeAssumptionParser {
|
|||||||
.withToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR));
|
.withToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR));
|
||||||
}
|
}
|
||||||
int i = Integer.parseInt(input.substring(1));
|
int i = Integer.parseInt(input.substring(1));
|
||||||
variables.add(new TypeVariable(TypeVariableKind.USER_INPUT, i));
|
TypeVariable variable = new TypeVariable(TypeVariableKind.USER_INPUT, i);
|
||||||
|
if (variables.contains(variable)) {
|
||||||
|
return new ParserResult<>(ParseError.UNEXPECTED_TOKEN
|
||||||
|
.withToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR));
|
||||||
|
}
|
||||||
|
variables.add(variable);
|
||||||
expectCommaOrDot = true;
|
expectCommaOrDot = true;
|
||||||
return new ParserResult<>(this);
|
return new ParserResult<>(this);
|
||||||
case COMMA:
|
case COMMA:
|
||||||
|
@ -228,6 +228,17 @@ class TypeAssumptionParserTest {
|
|||||||
assertTrue(expected.contains(Token.TokenType.COMMA));
|
assertTrue(expected.contains(Token.TokenType.COMMA));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void doesntAcceptDuplicateQuantifiedVariables() {
|
||||||
|
TypeAssumptionParser parser = new TypeAssumptionParser();
|
||||||
|
Result<Map<VarTerm, TypeAbstraction>, ParseError> type = parser.parse("id: ∀ t1, t1 : t1 -> t1");
|
||||||
|
assertTrue(type.isError());
|
||||||
|
ParseError error = type.unwrapError();
|
||||||
|
assertEquals(ParseError.UNEXPECTED_TOKEN, error);
|
||||||
|
assertEquals(Token.TokenType.VARIABLE, error.getCause().get().getType());
|
||||||
|
assertEquals(10, error.getCause().get().getPos());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void errors() {
|
void errors() {
|
||||||
Map<String, ParseError> tests = new HashMap<>();
|
Map<String, ParseError> tests = new HashMap<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user