diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 11:48:37 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 11:48:37 +0100 |
| commit | a409b4f6576980f876ec880ddf24dadc5d418c58 (patch) | |
| tree | 58432c2074f8ce8232ffc77c8c039788a690dc42 /src/main/java | |
| parent | 643d339ade252af66259466d9a9f615760471fc1 (diff) | |
Check struct type info is present
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java | 6 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/typechecker/errors/MissingStructTypeInfoError.java | 24 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java index 73713a65..bd5b43fd 100644 --- a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java @@ -411,7 +411,11 @@ public class TypeChecker { untyped.fieldName() ); - var fieldType = structTypeInfo.orElseThrow().fieldType(untyped.fieldName()); + if (structTypeInfo.isEmpty()) { + throw new MissingStructTypeInfoError(receiverType, untyped.source()); + } + + var fieldType = structTypeInfo.get().fieldType(untyped.fieldName()); if (fieldType.isEmpty()) { throw new NoSuchFieldError(receiverType, untyped.fieldName(), untyped.source()); diff --git a/src/main/java/org/shedlang/compiler/typechecker/errors/MissingStructTypeInfoError.java b/src/main/java/org/shedlang/compiler/typechecker/errors/MissingStructTypeInfoError.java new file mode 100644 index 00000000..b7582135 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/typechecker/errors/MissingStructTypeInfoError.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.typechecker.errors; + +import org.shedlang.compiler.errors.InternalCompilerError; +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.types.StructType; + +public class MissingStructTypeInfoError extends InternalCompilerError { + private final StructType type; + private final Source source; + + public MissingStructTypeInfoError(StructType type, Source source) { + super("Missing type info for struct " + type); + this.type = type; + this.source = source; + } + + public StructType type() { + return type; + } + + public Source source() { + return source; + } +} |
