Skip to content

Commit 8396531

Browse files
committed
Started moving to InvalidTypeID of BasicTypeID.Invalid
1 parent 7d17ef5 commit 8396531

6 files changed

Lines changed: 14 additions & 3 deletions

File tree

CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CastedExpression.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.openzen.zenscript.codemodel.expression.Expression;
66
import org.openzen.zenscript.codemodel.expression.InvalidExpression;
77
import org.openzen.zenscript.codemodel.type.BasicTypeID;
8+
import org.openzen.zenscript.codemodel.type.InvalidTypeID;
89

910
public class CastedExpression {
1011
public enum Level {
@@ -63,7 +64,7 @@ public CastedExpression(Level level, Expression value) {
6364

6465
public CastedExpression(CodePosition position, CompileError error) {
6566
this.level = Level.INVALID;
66-
this.value = new InvalidExpression(position, BasicTypeID.INVALID, error);
67+
this.value = new InvalidExpression(position, new InvalidTypeID(position, error), error);
6768
this.error = error;
6869
}
6970

CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CompileErrors.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ public static CompileError returnValueInVoidFunction() {
498498
return new CompileError(CompileExceptionCode.RETURN_VALUE_VOID, "Return type is void; cannot return a value");
499499
}
500500

501+
public static CompileError missingThrownType() {
502+
return new CompileError(CompileExceptionCode.MISSING_THROWN_TYPE, "Statement doesn't throw anything");
503+
}
504+
501505
public static CompileError missingReturn() {
502506
return new CompileError(CompileExceptionCode.MISSING_RETURN, "Missing return");
503507
}

CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/impl/compiler/ExpressionCompilerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public Expression interfaceCast(ImplementationMemberInstance implementation, Exp
309309

310310
@Override
311311
public Expression invalid(CompileError error) {
312-
return new InvalidExpression(position, BasicTypeID.INVALID, error);
312+
return new InvalidExpression(position, new InvalidTypeID(position, error), error);
313313
}
314314

315315
@Override

Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.openzen.zenscript.parser.statements;
22

33
import org.openzen.zencode.shared.CodePosition;
4+
import org.openzen.zenscript.codemodel.compilation.CompileErrors;
45
import org.openzen.zenscript.codemodel.compilation.CompilingVariable;
56
import org.openzen.zenscript.codemodel.compilation.StatementCompiler;
67
import org.openzen.zenscript.codemodel.compilation.statement.CompilingStatement;
@@ -9,6 +10,7 @@
910
import org.openzen.zenscript.codemodel.statement.VarStatement;
1011
import org.openzen.zenscript.codemodel.statement.VariableID;
1112
import org.openzen.zenscript.codemodel.type.BasicTypeID;
13+
import org.openzen.zenscript.codemodel.type.InvalidTypeID;
1214
import org.openzen.zenscript.codemodel.type.TypeID;
1315

1416
public class ParsedCatchClause {
@@ -40,7 +42,7 @@ public Compiling(StatementCompiler compiler, CompilingVariable exceptionVariable
4042
}
4143

4244
public CatchClause complete() {
43-
TypeID exceptionType = compiler.expressions().getThrowableType().orElse(BasicTypeID.INVALID);
45+
TypeID exceptionType = compiler.expressions().getThrowableType().orElse(new InvalidTypeID(position, CompileErrors.missingThrownType()));
4446
VarStatement exceptionVariable = new VarStatement(position, this.exceptionVariable.id, this.exceptionVariable.name, exceptionType, null, true);
4547
return new CatchClause(position, exceptionVariable, content.complete());
4648
}

Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public enum CompileExceptionCode {
129129
INVALID_CALL_ARGUMENT,
130130
NO_ACCESS,
131131
MISSING_RETURN_VALUE,
132+
MISSING_THROWN_TYPE,
132133
TRY_CATCH_RESOURCE_REQUIRES_INITIALIZER,
133134
INVALID_SUPERCLASS,
134135
INVALID_OVERRIDE,

Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public Void visitBasic(TypeContext context, BasicTypeID basic) {
3232
if (basic == BasicTypeID.UNDETERMINED)
3333
validator.logError(position, CompileErrors.typeNotDetermined(context.display));
3434

35+
if (basic.isInvalid()) {
36+
validator.logError(position, CompileErrors.invalidType());
37+
}
3538
return null;
3639
}
3740

0 commit comments

Comments
 (0)