aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-02 19:22:23 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-02 19:22:23 +0000
commitec9845967d37ad678249e9857e253af4c04e8e4e (patch)
treee1f2d552c29c6e7959c02b8d6ae153b6e485b4c2 /src/test/java
parentfe0cb0f6ed1be2da385a10fcb72734b5e01d57ca (diff)
Type check native type methods
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNativeTypeDeclarationTests.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNativeTypeDeclarationTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNativeTypeDeclarationTests.java
index c9dca725..938b6075 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNativeTypeDeclarationTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNativeTypeDeclarationTests.java
@@ -2,14 +2,19 @@ package org.shedlang.compiler.typechecker;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.ast.untyped.Untyped;
+import org.shedlang.compiler.ast.untyped.UntypedNativeFunctionDeclarationNode;
import org.shedlang.compiler.ast.untyped.UntypedNativeTypeDeclarationNode;
import org.shedlang.compiler.typechecker.errors.CannotDefineNativeTypeOutsideOfNamespaceError;
+import org.shedlang.compiler.types.FunctionType;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.types.Types;
+import org.shedlang.compiler.util.P;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.shedlang.compiler.ast.typed.TypedNodeMatchers.isTypedNativeFunctionDeclarationNode;
import static org.shedlang.compiler.ast.typed.TypedNodeMatchers.isTypedNativeTypeDeclarationNode;
import static org.shedlang.compiler.typechecker.TypeCheckerTesting.typeCheckNamespaceStatement;
import static org.shedlang.compiler.types.TypeMatchers.*;
@@ -119,4 +124,37 @@ public class TypeCheckerNativeTypeDeclarationTests {
))
);
}
+
+ @Test
+ public void canTypeCheckMethodWithOnlyThisParam() {
+ var untyped = UntypedNativeTypeDeclarationNode.builder()
+ .withName("ExampleType")
+ .addMethod(
+ UntypedNativeFunctionDeclarationNode.builder()
+ .addPositionalParam(Untyped.typeLevelReference("This"))
+ .withName("a")
+ .withReturnType(Untyped.typeLevelReference("Unit"))
+ .build()
+ )
+ .build();
+ var context = TypeCheckerContext.EMPTY
+ .enterGlobal(P.map(
+ Map.entry("Unit", Types.metaType(Types.UNIT))
+ ));
+
+ var typed = typeCheckNamespaceStatement(untyped, context);
+
+ assertThat(
+ typed.value(),
+ isTypedNativeTypeDeclarationNode()
+ .withMethods(isSequence(
+ isTypedNativeFunctionDeclarationNode()
+ .withSignature(
+ FunctionType.builder()
+ .addPositionalParam(Types.nativeType(NAMESPACE_NAME, "ExampleType"))
+ .build()
+ )
+ ))
+ );
+ }
}