aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerValTests.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerValTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerValTests.java
index 7967e442..f09c73e9 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerValTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerValTests.java
@@ -3,6 +3,7 @@ package org.shedlang.compiler.typechecker;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.ast.untyped.Untyped;
import org.shedlang.compiler.ast.untyped.UntypedFunctionDefinitionNode;
+import org.shedlang.compiler.typechecker.errors.DuplicateVariableName;
import org.shedlang.compiler.typechecker.errors.ReferenceBeforeDefinitionError;
import org.shedlang.compiler.types.Types;
import org.shedlang.compiler.util.P;
@@ -88,4 +89,23 @@ public class TypeCheckerValTests {
assertThat(error.variableName(), equalTo("x"));
}
+
+ @Test
+ public void duplicateVariableNamesAreNotAllowed() {
+ var untyped = UntypedFunctionDefinitionNode.builder()
+ .addStatement(Untyped.val(Untyped.targetVariable("x"), Untyped.stringLiteral("hello")))
+ .addStatement(Untyped.val(Untyped.targetVariable("x"), Untyped.stringLiteral("hello")))
+ .build();
+ var context = TypeCheckerContext.EMPTY
+ .enterBlockWithDefinedVariables(P.map(
+ Map.entry("Unit", Types.metaType(Types.UNIT))
+ ));
+
+ var error = assertThrows(
+ DuplicateVariableName.class,
+ () -> TypeChecker.typeCheckNamespaceStatement(untyped, context)
+ );
+
+ assertThat(error.variableName(), equalTo("x"));
+ }
}