diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-12-04 11:39:37 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-12-04 11:43:08 +0000 |
| commit | 310ab73f591a5cdee976bcf1b420f993db100b62 (patch) | |
| tree | a98774d1d3850aa95782f4aaf590eab968165369 /src/main/java | |
| parent | 393226f2b6e494045da5e447fb3bfffe3ef71d11 (diff) | |
Type where call properly
Diffstat (limited to 'src/main/java')
3 files changed, 27 insertions, 7 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java index 0adeb12..1c6a2cf 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java @@ -906,22 +906,29 @@ public class TypeChecker { throw noSuchMemberError; } - var typeLevelValue = switch (receiverType.value()) { + var type = switch (receiverType.value()) { case DatabaseSchema databaseSchema -> { var schemaInfo = context.databaseSchemaInfo(databaseSchema); var tableInfo = schemaInfo.tables().get(untyped.memberName()); if (tableInfo == null) { throw noSuchMemberError; } - yield tableInfo.table(); + yield Types.table(tableInfo.table()); } case Table table -> { switch (untyped.memberName()) { - case "where": - yield new RelationMethod(new RelationTable(table), "where"); + case "where" -> { + var schemaInfo = context.databaseSchemaInfo(table.databaseSchema()); + var tableInfo = schemaInfo.tables().get(table.name()); + var rowType = tableInfo.rowType(); + yield new FunctionType( + List.of(new FunctionType(List.of(rowType), NativeTypes.BOOL)), + new RelationType(rowType) + ); + } - default: + default -> throw noSuchMemberError; } } @@ -934,7 +941,7 @@ public class TypeChecker { return new TypedMemberAccessNode( receiver, untyped.memberName(), - new TypeLevelValueType(typeLevelValue), + type, untyped.source() ); } diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/RelationType.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/RelationType.java new file mode 100644 index 0000000..0219683 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/RelationType.java @@ -0,0 +1,13 @@ +package org.zwobble.hobgoblin.compiler.types; + +public record RelationType(StructType rowType) implements Type { + @Override + public String name() { + return "Relation"; + } + + @Override + public String describe() { + return "Relation[" + rowType.describe() + "]"; + } +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java index 41e1f74..9ef4bf7 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java @@ -1,5 +1,5 @@ package org.zwobble.hobgoblin.compiler.types; -public sealed interface Type extends TypeLevelValue permits ConstructedNativeType, ConstructedStructType, ConstructedType, ConstructibleType, EnumType, FunctionType, SimpleNativeType, SimpleStructType, SimpleType, StructType, SumType, TypeLevelValueType, TypeParam { +public sealed interface Type extends TypeLevelValue permits ConstructedNativeType, ConstructedStructType, ConstructedType, ConstructibleType, EnumType, FunctionType, RelationType, SimpleNativeType, SimpleStructType, SimpleType, StructType, SumType, TypeLevelValueType, TypeParam { String name(); } |
