From 310ab73f591a5cdee976bcf1b420f993db100b62 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 4 Dec 2026 11:39:37 +0000 Subject: Type where call properly --- .../hobgoblin/compiler/typechecker/TypeChecker.java | 19 +++++++++++++------ .../hobgoblin/compiler/types/RelationType.java | 13 +++++++++++++ .../org/zwobble/hobgoblin/compiler/types/Type.java | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/types/RelationType.java (limited to 'src/main/java/org/zwobble') 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(); } -- cgit v1.2.3