From 6ea1e107ed1358e809e24681bc22284d4aa7e630 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 23 Dec 2023 16:49:29 +0000 Subject: Create type constructor for structs with type params --- .../ast/typed/TypedStructDefinitionNodeMatcher.java | 16 ++++++++++++++-- .../java/org/shedlang/compiler/ast/untyped/Untyped.java | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/test/java/org/shedlang/compiler/ast') diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java index 46f0438f..6dd41fe8 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java @@ -3,11 +3,13 @@ package org.shedlang.compiler.ast.typed; import org.pcollections.PVector; import org.shedlang.compiler.testing.MatcherBuilder; import org.shedlang.compiler.types.StructType; -import org.shedlang.compiler.types.UserDefinedEffect; +import org.shedlang.compiler.types.TypeConstructor; +import org.shedlang.compiler.types.TypeOrConstructor; import org.shedlang.compiler.util.P; import org.zwobble.precisely.Matcher; import static org.zwobble.precisely.Matchers.has; +import static org.zwobble.precisely.Matchers.instanceOf; public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< TypedNamespaceStatementNode, @@ -33,7 +35,17 @@ public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< } public TypedStructDefinitionNodeMatcher withType(Matcher type) { - return with(has("type", x -> x.type(), type)); + return with(has("typeOrConstructor", x -> x.typeOrConstructor(), instanceOf( + TypeOrConstructor.Type.class, + has("value", x -> x.value(), instanceOf(StructType.class, type)) + ))); + } + + public TypedStructDefinitionNodeMatcher withTypeConstructor(Matcher> type) { + return with(has("typeOrConstructor", x -> x.typeOrConstructor(), instanceOf( + TypeOrConstructor.Constructor.class, + has("value", x -> (TypeConstructor) x.value(), type) + ))); } public TypedStructDefinitionNodeMatcher withFields( diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java index 8d105dd9..559ca461 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java @@ -224,6 +224,10 @@ public class Untyped { return new UntypedTupleTypeNode(elements, Sources.NULL); } + public static UntypedTypeLevelParamNode typeLevelParam(String name) { + return new UntypedTypeLevelParamNode(name, Sources.NULL); + } + public static UntypedTypeLevelReferenceNode typeLevelReference(String name) { return new UntypedTypeLevelReferenceNode(name, Sources.NULL); } -- cgit v1.2.3