Browse Source

- Made important modifications to error reporting so it provides meaningful info

- Fix various normalization bugs
- Fixed bugs with the new stored type system
Stan Hebben 6 years ago
parent
commit
bd90cfe0be
100 changed files with 583 additions and 482 deletions
  1. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java
  2. 19
    12
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionForMethod.java
  3. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  4. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java
  5. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  6. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java
  8. 0
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InvalidExpression.java
  9. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MatchExpression.java
  10. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/VariantValueExpression.java
  11. 9
    8
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java
  12. 6
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java
  13. 5
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java
  14. 6
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialPackageExpression.java
  15. 5
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  16. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java
  17. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialVariantOptionExpression.java
  18. 8
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java
  19. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java
  20. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java
  21. 5
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  22. 7
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  23. 4
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  24. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java
  25. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  26. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java
  27. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java
  28. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java
  29. 5
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java
  30. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java
  31. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java
  32. 5
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/IfStatement.java
  33. 6
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java
  34. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  35. 5
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java
  36. 14
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java
  37. 1
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java
  38. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java
  39. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java
  40. 8
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  41. 93
    125
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberGroup.java
  42. 12
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  43. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageTag.java
  44. 4
    3
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  45. 5
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  46. 4
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java
  47. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  48. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  49. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  50. 0
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  51. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  52. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  53. 2
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceStatementScope.java
  54. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  55. 7
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionParameter.java
  56. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java
  57. 5
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariantOption.java
  58. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedCallArguments.java
  59. 5
    8
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java
  60. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  61. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAndAnd.java
  62. 9
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java
  63. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAssign.java
  64. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBinary.java
  65. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java
  66. 26
    30
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  67. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCast.java
  68. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java
  69. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCompare.java
  70. 4
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionConditional.java
  71. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFloat.java
  72. 10
    6
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  73. 10
    9
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java
  74. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java
  75. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIs.java
  76. 10
    14
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java
  77. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java
  78. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOpAssign.java
  79. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOrOr.java
  80. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOuter.java
  81. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java
  82. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.java
  83. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSame.java
  84. 2
    11
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java
  85. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSuper.java
  86. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionUnary.java
  87. 2
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java
  88. 15
    21
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java
  89. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedPanicExpression.java
  90. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedThrowExpression.java
  91. 4
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryConvertExpression.java
  92. 4
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryRethrowExpression.java
  93. 6
    6
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java
  94. 15
    9
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java
  95. 8
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementDoWhile.java
  96. 7
    2
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementExpression.java
  97. 22
    16
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementForeach.java
  98. 9
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementIf.java
  99. 9
    3
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementLock.java
  100. 0
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementReturn.java

+ 12
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java View File

@@ -5,9 +5,13 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel;
7 7
 
8
+import java.util.ArrayList;
8 9
 import java.util.List;
10
+import org.openzen.zencode.shared.ConcatMap;
9 11
 import org.openzen.zencode.shared.Taggable;
10 12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13
+import org.openzen.zenscript.codemodel.scope.TypeScope;
14
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
11 15
 import org.openzen.zenscript.codemodel.statement.Statement;
12 16
 
13 17
 /**
@@ -28,4 +32,12 @@ public class ScriptBlock extends Taggable {
28 32
 		result.addAllTagsFrom(this);
29 33
 		return result;
30 34
 	}
35
+	
36
+	public ScriptBlock normalize(TypeScope scope) {
37
+		List<Statement> result = new ArrayList<>();
38
+		for (Statement statement : statements) {
39
+			result.add(statement.normalize(scope, ConcatMap.empty(LoopStatement.class, LoopStatement.class)));
40
+		}
41
+		return new ScriptBlock(pkg, result);
42
+	}
31 43
 }

+ 19
- 12
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionForMethod.java View File

@@ -9,6 +9,7 @@ import java.util.ArrayList;
9 9
 import java.util.Arrays;
10 10
 import java.util.List;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12 13
 import org.openzen.zenscript.codemodel.context.StatementContext;
13 14
 import org.openzen.zenscript.codemodel.context.TypeContext;
14 15
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -83,19 +84,25 @@ public class PreconditionForMethod implements MemberAnnotation {
83 84
 		if (body == null)
84 85
 			return body;
85 86
 		
86
-		ExpressionScope expressionScope = new ExpressionScope(scope, BasicTypeID.BOOL.stored);
87
-		List<Statement> statements = new ArrayList<>();
88
-		ExpressionBuilder expressionBuilder = new ExpressionBuilder(position, expressionScope);
89
-		Expression inverseCondition = expressionBuilder.not(condition);
90
-		Statement throwStatement = new ExpressionStatement(position, new PanicExpression(position, BasicTypeID.VOID.stored, message));
91
-		statements.add(new IfStatement(position, inverseCondition, throwStatement, null));
92
-		
93
-		if (body instanceof BlockStatement) {
94
-			statements.addAll(Arrays.asList(((BlockStatement)body).statements));
95
-		} else {
96
-			statements.add(body);
87
+		try {
88
+			ExpressionScope expressionScope = new ExpressionScope(scope, BasicTypeID.BOOL.stored);
89
+			List<Statement> statements = new ArrayList<>();
90
+			ExpressionBuilder expressionBuilder = new ExpressionBuilder(position, expressionScope);
91
+			Expression inverseCondition = expressionBuilder.not(condition);
92
+			Statement throwStatement = new ExpressionStatement(position, new PanicExpression(position, BasicTypeID.VOID.stored, message));
93
+			statements.add(new IfStatement(position, inverseCondition, throwStatement, null));
94
+
95
+			if (body instanceof BlockStatement) {
96
+				statements.addAll(Arrays.asList(((BlockStatement)body).statements));
97
+			} else {
98
+				statements.add(body);
99
+			}
100
+			return new BlockStatement(position, statements.toArray(new Statement[statements.size()]));
101
+		} catch (CompileException ex) {
102
+			// TODO
103
+			ex.printStackTrace();
104
+			return body;
97 105
 		}
98
-		return new BlockStatement(position, statements.toArray(new Statement[statements.size()]));
99 106
 	}
100 107
 
101 108
 	@Override

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java View File

@@ -25,7 +25,6 @@ import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
25 25
  */
26 26
 public class FunctionDefinition extends HighLevelDefinition {
27 27
 	public FunctionHeader header;
28
-	public Statement statement;
29 28
 	public CallerMember caller;
30 29
 	public final TypeMemberGroup callerGroup;
31 30
 	
@@ -46,7 +45,6 @@ public class FunctionDefinition extends HighLevelDefinition {
46 45
 	}
47 46
 	
48 47
 	public void setCode(Statement statement) {
49
-		this.statement = statement;
50 48
 		caller.setBody(statement);
51 49
 	}
52 50
 

+ 3
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java View File

@@ -45,12 +45,14 @@ public class VariantDefinition extends HighLevelDefinition {
45 45
 	}
46 46
 	
47 47
 	public static class Option extends Taggable {
48
+		public final CodePosition position;
48 49
 		public final VariantDefinition variant;
49 50
 		public final String name;
50 51
 		public final int ordinal;
51 52
 		public final StoredType[] types;
52 53
 		
53
-		public Option(VariantDefinition variant, String name, int ordinal, StoredType[] types) {
54
+		public Option(CodePosition position, VariantDefinition variant, String name, int ordinal, StoredType[] types) {
55
+			this.position = position;
54 56
 			this.variant = variant;
55 57
 			this.name = name;
56 58
 			this.ordinal = ordinal;

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java View File

@@ -9,10 +9,10 @@ import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12 13
 import org.openzen.zencode.shared.CompileExceptionCode;
13 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14 15
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
16 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17 17
 import org.openzen.zenscript.codemodel.partial.PartialPackageExpression;
18 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
@@ -50,13 +50,13 @@ public class ZSPackage {
50 50
 		subPackages.put(name, subPackage);
51 51
 	}
52 52
 	
53
-	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) {
53
+	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) throws CompileException {
54 54
 		if (subPackages.containsKey(name.name) && name.hasNoArguments())
55 55
 			return new PartialPackageExpression(position, subPackages.get(name.name));
56 56
 		
57 57
 		if (types.containsKey(name.name)) {
58 58
 			if (types.get(name.name).typeParameters.length != name.getNumberOfArguments())
59
-				return new InvalidExpression(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
59
+				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
60 60
 			
61 61
 			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments), name.arguments);
62 62
 		}

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java View File

@@ -11,6 +11,7 @@ import java.util.Objects;
11 11
 import java.util.function.Consumer;
12 12
 import java.util.stream.Collectors;
13 13
 import org.openzen.zencode.shared.CodePosition;
14
+import org.openzen.zencode.shared.CompileException;
14 15
 import org.openzen.zencode.shared.CompileExceptionCode;
15 16
 import org.openzen.zenscript.codemodel.FunctionHeader;
16 17
 import org.openzen.zenscript.codemodel.OperatorType;
@@ -116,7 +117,7 @@ public abstract class Expression implements IPartialExpression {
116 117
 	}
117 118
 	
118 119
 	@Override
119
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
120
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
120 121
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).call(position, scope, this, arguments, false);
121 122
 	}
122 123
 	

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java View File

@@ -64,7 +64,7 @@ public class ExpressionBuilder {
64 64
 				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
65 65
 	}
66 66
 	
67
-	public Expression not(Expression value) {
67
+	public Expression not(Expression value) throws CompileException {
68 68
 		TypeMembers members = scope.getTypeMembers(value.type);
69 69
 		return members.getOrCreateGroup(OperatorType.NOT)
70 70
 				.call(position, scope, value, CallArguments.EMPTY, false);

+ 0
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InvalidExpression.java View File

@@ -9,7 +9,6 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zencode.shared.CompileException;
10 10
 import org.openzen.zencode.shared.CompileExceptionCode;
11 11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
13 12
 import org.openzen.zenscript.codemodel.type.StoredType;
14 13
 
15 14
 /**
@@ -27,10 +26,6 @@ public class InvalidExpression extends Expression {
27 26
 		this.message = message;
28 27
 	}
29 28
 	
30
-	public InvalidExpression(CodePosition position, CompileExceptionCode code, String message) {
31
-		this(position, BasicTypeID.UNDETERMINED.stored, code, message);
32
-	}
33
-	
34 29
 	public InvalidExpression(StoredType type, CompileException cause) {
35 30
 		this(cause.position, type, cause.code, cause.getMessage());
36 31
 	}

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MatchExpression.java View File

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.statement.Statement;
16 16
 import org.openzen.zenscript.codemodel.statement.SwitchCase;
17 17
 import org.openzen.zenscript.codemodel.statement.SwitchStatement;
18 18
 import org.openzen.zenscript.codemodel.statement.VarStatement;
19
+import org.openzen.zenscript.codemodel.statement.VariableID;
19 20
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
20 21
 import org.openzen.zenscript.codemodel.type.StoredType;
21 22
 
@@ -65,7 +66,7 @@ public class MatchExpression extends Expression {
65 66
 	}
66 67
 	
67 68
 	public SwitchedMatch convertToSwitch(String tempVariable) {
68
-		VarStatement result = new VarStatement(position, tempVariable, type, null, false);
69
+		VarStatement result = new VarStatement(position, new VariableID(), tempVariable, type, null, false);
69 70
 		SwitchStatement switchStatement = new SwitchStatement(position, null, value);
70 71
 		boolean hasDefault = false;
71 72
 		for (MatchExpression.Case matchCase : cases) {

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/VariantValueExpression.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import java.util.List;
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
11 12
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12 13
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -35,7 +36,7 @@ public class VariantValueExpression extends Expression {
35 36
 	}
36 37
 	
37 38
 	@Override
38
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
39
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
39 40
 		if (arguments != null)
40 41
 			return super.call(position, scope, hints, arguments);
41 42
 		
@@ -62,7 +63,7 @@ public class VariantValueExpression extends Expression {
62 63
 	public Expression normalize(TypeScope scope) {
63 64
 		Expression[] normalized = new Expression[arguments.length];
64 65
 		for (int i = 0; i < normalized.length; i++)
65
-			normalized[i] = arguments[i].normalize(scope);
66
+			normalized[i] = arguments[i].normalize(scope).castImplicit(position, scope, option.types[i]);
66 67
 		return new VariantValueExpression(position, type, option, normalized);
67 68
 	}
68 69
 }

+ 9
- 8
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.codemodel.partial;
8 8
 import java.util.Collections;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
@@ -29,15 +30,15 @@ public interface IPartialExpression {
29 30
 		return Collections.emptyList();
30 31
 	}
31 32
 	
32
-	Expression eval();
33
+	Expression eval() throws CompileException;
33 34
 	
34
-	List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments);
35
+	List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException;
35 36
 	
36
-	List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments);
37
+	List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException;
37 38
 	
38
-	IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name);
39
+	IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException;
39 40
 	
40
-	Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments);
41
+	Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException;
41 42
 	
42 43
 	TypeID[] getGenericCallTypes();
43 44
 	
@@ -50,11 +51,11 @@ public interface IPartialExpression {
50 51
 		return null;
51 52
 	}
52 53
 	
53
-	default Expression assign(CodePosition position, TypeScope scope, Expression value) {
54
+	default Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
54 55
 		return new InvalidExpression(position, value.type, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
55 56
 	}
56 57
 	
57
-	default IPartialExpression capture(CodePosition position, LambdaClosure closure) {
58
-		return new InvalidExpression(position, CompileExceptionCode.UNAVAILABLE_IN_CLOSURE, "expression not allowed in closure");
58
+	default IPartialExpression capture(CodePosition position, LambdaClosure closure) throws CompileException {
59
+		throw new CompileException(position, CompileExceptionCode.UNAVAILABLE_IN_CLOSURE, "expression not allowed in closure");
59 60
 	}
60 61
 }

+ 6
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.partial;
7 7
 
8 8
 import java.util.List;
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -35,27 +36,27 @@ public class PartialGlobalExpression implements IPartialExpression {
35 36
 	}
36 37
 	
37 38
 	@Override
38
-	public Expression eval() {
39
+	public Expression eval() throws CompileException {
39 40
 		return new GlobalExpression(position, name, resolution.eval());
40 41
 	}
41 42
 
42 43
 	@Override
43
-	public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) {
44
+	public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
44 45
 		return resolution.predictCallTypes(scope, hints, arguments);
45 46
 	}
46 47
 
47 48
 	@Override
48
-	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) {
49
+	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
49 50
 		return resolution.getPossibleFunctionHeaders(scope, hints, arguments);
50 51
 	}
51 52
 
52 53
 	@Override
53
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
54
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
54 55
 		return eval().getMember(position, scope, hints, name);
55 56
 	}
56 57
 
57 58
 	@Override
58
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
59
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
59 60
 		return new GlobalCallExpression(position, name, arguments, resolution.call(position, scope, hints, arguments));
60 61
 	}
61 62
 

+ 5
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java View File

@@ -68,7 +68,7 @@ public class PartialMemberGroupExpression implements IPartialExpression {
68 68
 	}
69 69
 
70 70
 	@Override
71
-	public Expression eval() {
71
+	public Expression eval() throws CompileException {
72 72
 		return group.getter(position, scope, target, allowStaticUsage);
73 73
 	}
74 74
 	
@@ -107,22 +107,22 @@ public class PartialMemberGroupExpression implements IPartialExpression {
107 107
 	}
108 108
 
109 109
 	@Override
110
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
110
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
111 111
 		return eval().getMember(position, scope, hints, name);
112 112
 	}
113 113
 
114 114
 	@Override
115
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
115
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
116 116
 		return group.call(position, scope, target, arguments, allowStaticUsage);
117 117
 	}
118 118
 	
119 119
 	@Override
120
-	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
120
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
121 121
 		return group.setter(position, scope, target, value, allowStaticUsage);
122 122
 	}
123 123
 	
124 124
 	@Override
125
-	public IPartialExpression capture(CodePosition position, LambdaClosure closure) {
125
+	public IPartialExpression capture(CodePosition position, LambdaClosure closure) throws CompileException {
126 126
 		return new PartialMemberGroupExpression(position, scope, target.capture(position, closure).eval(), group, typeArguments, allowStaticUsage);
127 127
 	}
128 128
 

+ 6
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialPackageExpression.java View File

@@ -8,12 +8,12 @@ package org.openzen.zenscript.codemodel.partial;
8 8
 import java.util.Collections;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14 15
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15 16
 import org.openzen.zenscript.codemodel.expression.Expression;
16
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
17 17
 import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.scope.TypeScope;
19 19
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -33,8 +33,8 @@ public class PartialPackageExpression implements IPartialExpression {
33 33
 	}
34 34
 	
35 35
 	@Override
36
-	public Expression eval() {
37
-		return new InvalidExpression(position, CompileExceptionCode.USING_PACKAGE_AS_EXPRESSION, "Cannot evaluate a package as expression");
36
+	public Expression eval() throws CompileException {
37
+		throw new CompileException(position, CompileExceptionCode.USING_PACKAGE_AS_EXPRESSION, "Cannot evaluate a package as expression");
38 38
 	}
39 39
 
40 40
 	@Override
@@ -48,13 +48,13 @@ public class PartialPackageExpression implements IPartialExpression {
48 48
 	}
49 49
 
50 50
 	@Override
51
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
51
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
52 52
 		return pkg.getMember(position, scope.getTypeRegistry(), name);
53 53
 	}
54 54
 
55 55
 	@Override
56
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
57
-		return new InvalidExpression(position, CompileExceptionCode.USING_PACKAGE_AS_CALL_TARGET, "Cannot call a package");
56
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
57
+		throw new CompileException(position, CompileExceptionCode.USING_PACKAGE_AS_CALL_TARGET, "Cannot call a package");
58 58
 	}
59 59
 
60 60
 	@Override

+ 5
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java View File

@@ -9,6 +9,7 @@ import java.util.Collections;
9 9
 import java.util.List;
10 10
 import java.util.stream.Collectors;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14 15
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -46,7 +47,7 @@ public class PartialStaticMemberGroupExpression implements IPartialExpression {
46 47
 	}
47 48
 	
48 49
 	@Override
49
-	public Expression eval() {
50
+	public Expression eval() throws CompileException {
50 51
 		return group.staticGetter(position, scope);
51 52
 	}
52 53
 
@@ -64,17 +65,17 @@ public class PartialStaticMemberGroupExpression implements IPartialExpression {
64 65
 	}
65 66
 
66 67
 	@Override
67
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
68
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
68 69
 		return eval().getMember(position, scope, hints, name);
69 70
 	}
70 71
 
71 72
 	@Override
72
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
73
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
73 74
 		return group.callStatic(position, target, scope, arguments);
74 75
 	}
75 76
 	
76 77
 	@Override
77
-	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
78
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
78 79
 		return group.staticSetter(position, scope, value);
79 80
 	}
80 81
 

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.codemodel.partial;
8 8
 import java.util.List;
9 9
 import java.util.stream.Collectors;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.OperatorType;
@@ -62,7 +63,7 @@ public class PartialTypeExpression implements IPartialExpression {
62 63
 	}
63 64
 
64 65
 	@Override
65
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
66
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
66 67
 		if (arguments.getNumberOfTypeArguments() == 0 && (typeParameters != null && typeParameters.length > 0))
67 68
 			arguments = new CallArguments(typeParameters, arguments.arguments);
68 69
 		

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialVariantOptionExpression.java View File

@@ -9,6 +9,7 @@ import java.util.Arrays;
9 9
 import java.util.Collections;
10 10
 import java.util.List;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12 13
 import org.openzen.zencode.shared.CompileExceptionCode;
13 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 15
 import org.openzen.zenscript.codemodel.expression.CallArguments;
@@ -58,8 +59,8 @@ public class PartialVariantOptionExpression implements IPartialExpression {
58 59
 	}
59 60
 
60 61
 	@Override
61
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
62
-		return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "Variant options don't have members");
62
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
63
+		throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Variant options don't have members");
63 64
 	}
64 65
 
65 66
 	@Override

+ 8
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java View File

@@ -5,8 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8
-import java.util.function.Function;
9 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -21,7 +21,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMembers;
21 21
  * @author Hoofdgebruiker
22 22
  */
23 23
 public abstract class BaseScope implements TypeScope {
24
-	public abstract IPartialExpression get(CodePosition position, GenericName name);
24
+	public abstract IPartialExpression get(CodePosition position, GenericName name) throws CompileException;
25 25
 	
26 26
 	public abstract LoopStatement getLoop(String name);
27 27
 	
@@ -37,7 +37,11 @@ public abstract class BaseScope implements TypeScope {
37 37
 		return getMemberCache().getRegistry();
38 38
 	}
39 39
 	
40
-	public abstract Function<CodePosition, Expression> getDollar();
40
+	public abstract DollarEvaluator getDollar();
41 41
 	
42
-	public abstract IPartialExpression getOuterInstance(CodePosition position);
42
+	public abstract IPartialExpression getOuterInstance(CodePosition position) throws CompileException;
43
+	
44
+	public interface DollarEvaluator {
45
+		Expression apply(CodePosition position) throws CompileException;
46
+	}
43 47
 }

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java View File

@@ -6,12 +6,11 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
17 16
 import org.openzen.zenscript.codemodel.type.GenericName;
@@ -38,7 +37,7 @@ public class BlockScope extends StatementScope {
38 37
 	}
39 38
 	
40 39
 	@Override
41
-	public IPartialExpression get(CodePosition position, GenericName name) {
40
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
42 41
 		IPartialExpression fromSuper = super.get(position, name);
43 42
 		if (fromSuper != null)
44 43
 			return fromSuper;
@@ -72,12 +71,12 @@ public class BlockScope extends StatementScope {
72 71
 	}
73 72
 
74 73
 	@Override
75
-	public Function<CodePosition, Expression> getDollar() {
74
+	public DollarEvaluator getDollar() {
76 75
 		return parent.getDollar();
77 76
 	}
78 77
 	
79 78
 	@Override
80
-	public IPartialExpression getOuterInstance(CodePosition position) {
79
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
81 80
 		return parent.getOuterInstance(position);
82 81
 	}
83 82
 

+ 3
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java View File

@@ -8,12 +8,11 @@ package org.openzen.zenscript.codemodel.scope;
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11
-import java.util.function.Function;
12 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 14
 import org.openzen.zenscript.codemodel.GenericMapper;
15 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
16
-import org.openzen.zenscript.codemodel.expression.Expression;
17 16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18 17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
@@ -47,7 +46,7 @@ public class CompileTypeScope extends BaseScope {
47 46
 	}
48 47
 
49 48
 	@Override
50
-	public IPartialExpression get(CodePosition position, GenericName name) {
49
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
51 50
 		if (typeParameters.containsKey(name.name) && !name.hasArguments())
52 51
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)), name.arguments);
53 52
 
@@ -83,7 +82,7 @@ public class CompileTypeScope extends BaseScope {
83 82
 	}
84 83
 
85 84
 	@Override
86
-	public Function<CodePosition, Expression> getDollar() {
85
+	public DollarEvaluator getDollar() {
87 86
 		return outer.getDollar();
88 87
 	}
89 88
 

+ 5
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java View File

@@ -8,9 +8,9 @@ package org.openzen.zenscript.codemodel.scope;
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11
-import java.util.function.Function;
12 11
 import java.util.function.Supplier;
13 12
 import org.openzen.zencode.shared.CodePosition;
13
+import org.openzen.zencode.shared.CompileException;
14 14
 import org.openzen.zencode.shared.CompileExceptionCode;
15 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
16 16
 
@@ -19,7 +19,6 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
19 19
 import org.openzen.zenscript.codemodel.GenericMapper;
20 20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
21 21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22
-import org.openzen.zenscript.codemodel.expression.Expression;
23 22
 import org.openzen.zenscript.codemodel.expression.InvalidExpression;
24 23
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
25 24
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -93,7 +92,7 @@ public class DefinitionScope extends BaseScope {
93 92
 	}
94 93
 
95 94
 	@Override
96
-	public IPartialExpression get(CodePosition position, GenericName name) {
95
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
97 96
 		if (members != null) {
98 97
 			if (members.hasInnerType(name.name))
99 98
 				return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
@@ -150,14 +149,14 @@ public class DefinitionScope extends BaseScope {
150 149
 	}
151 150
 
152 151
 	@Override
153
-	public Function<CodePosition, Expression> getDollar() {
152
+	public DollarEvaluator getDollar() {
154 153
 		return outer.getDollar();
155 154
 	}
156 155
 	
157 156
 	@Override
158
-	public IPartialExpression getOuterInstance(CodePosition position) {
157
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
159 158
 		if (!definition.isInnerDefinition()) {
160
-			return new InvalidExpression(position, CompileExceptionCode.NO_OUTER_BECAUSE_NOT_INNER, "Type is not an inner type; cannot access outer type");
159
+			throw new CompileException(position, CompileExceptionCode.NO_OUTER_BECAUSE_NOT_INNER, "Type is not an inner type; cannot access outer type");
161 160
 		} else if (definition.isStatic()) {
162 161
 			return new InvalidExpression(position, outer.getThisType(), CompileExceptionCode.NO_OUTER_BECAUSE_STATIC, "Inner type is static; cannot access outer type reference");
163 162
 		} else {

+ 7
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java View File

@@ -11,6 +11,7 @@ import java.util.List;
11 11
 import java.util.Map;
12 12
 import java.util.function.Function;
13 13
 import org.openzen.zencode.shared.CodePosition;
14
+import org.openzen.zencode.shared.CompileException;
14 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 16
 import org.openzen.zenscript.codemodel.FunctionHeader;
16 17
 import org.openzen.zenscript.codemodel.GenericMapper;
@@ -36,7 +37,7 @@ import org.openzen.zenscript.codemodel.type.TypeID;
36 37
  */
37 38
 public class ExpressionScope extends BaseScope {
38 39
 	private final BaseScope outer;
39
-	private final Function<CodePosition, Expression> dollar;
40
+	private final DollarEvaluator dollar;
40 41
 	
41 42
 	public final List<StoredType> hints;
42 43
 	public final Map<TypeParameter, TypeID> genericInferenceMap;
@@ -66,7 +67,7 @@ public class ExpressionScope extends BaseScope {
66 67
 	private ExpressionScope(
67 68
 			BaseScope scope,
68 69
 			List<StoredType> hints,
69
-			Function<CodePosition, Expression> dollar,
70
+			DollarEvaluator dollar,
70 71
 			Map<TypeParameter, TypeID> genericInferenceMap,
71 72
 			Map<String, Function<CodePosition, Expression>> innerVariables) {
72 73
 		this.outer = scope;
@@ -100,7 +101,7 @@ public class ExpressionScope extends BaseScope {
100 101
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
101 102
 	}
102 103
 	
103
-	public ExpressionScope createInner(List<StoredType> hints, Function<CodePosition, Expression> dollar) {
104
+	public ExpressionScope createInner(List<StoredType> hints, DollarEvaluator dollar) {
104 105
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
105 106
 	}
106 107
 	
@@ -121,7 +122,7 @@ public class ExpressionScope extends BaseScope {
121 122
 	}
122 123
 	
123 124
 	@Override
124
-	public IPartialExpression get(CodePosition position, GenericName name) {
125
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
125 126
 		if (name.hasNoArguments() && innerVariables.containsKey(name.name))
126 127
 			return innerVariables.get(name.name).apply(position);
127 128
 		
@@ -154,12 +155,12 @@ public class ExpressionScope extends BaseScope {
154 155
 	}
155 156
 
156 157
 	@Override
157
-	public Function<CodePosition, Expression> getDollar() {
158
+	public DollarEvaluator getDollar() {
158 159
 		return dollar == null ? outer.getDollar() : dollar;
159 160
 	}
160 161
 	
161 162
 	@Override
162
-	public IPartialExpression getOuterInstance(CodePosition position) {
163
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
163 164
 		return outer.getOuterInstance(position);
164 165
 	}
165 166
 

+ 4
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java View File

@@ -8,16 +8,14 @@ package org.openzen.zenscript.codemodel.scope;
8 8
 import java.util.Collections;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11
-import java.util.function.Function;
12 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13 13
 import org.openzen.zencode.shared.CompileExceptionCode;
14 14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 15
 import org.openzen.zenscript.codemodel.FunctionHeader;
16 16
 import org.openzen.zenscript.codemodel.GenericMapper;
17 17
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18 18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
-import org.openzen.zenscript.codemodel.expression.Expression;
20
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
21 19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
22 20
 import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
23 21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
@@ -114,13 +112,13 @@ public class FileScope extends BaseScope {
114 112
 	}
115 113
 
116 114
 	@Override
117
-	public Function<CodePosition, Expression> getDollar() {
115
+	public DollarEvaluator getDollar() {
118 116
 		return null;
119 117
 	}
120 118
 	
121 119
 	@Override
122
-	public IPartialExpression getOuterInstance(CodePosition position) {
123
-		return new InvalidExpression(position, CompileExceptionCode.NO_OUTER_BECAUSE_OUTSIDE_TYPE, "Not in an inner type");
120
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
121
+		throw new CompileException(position, CompileExceptionCode.NO_OUTER_BECAUSE_OUTSIDE_TYPE, "Not in an inner type");
124 122
 	}
125 123
 
126 124
 	@Override

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java View File

@@ -6,12 +6,11 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15 14
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
16 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17 16
 import org.openzen.zenscript.codemodel.statement.ForeachStatement;
@@ -43,7 +42,7 @@ public class ForeachScope extends StatementScope {
43 42
 	}
44 43
 
45 44
 	@Override
46
-	public IPartialExpression get(CodePosition position, GenericName name) {
45
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
47 46
 		if (name.hasNoArguments()) {
48 47
 			for (VarStatement loopVariable : statement.loopVariables) {
49 48
 				if (loopVariable.name.equals(name.name))
@@ -92,12 +91,12 @@ public class ForeachScope extends StatementScope {
92 91
 	}
93 92
 
94 93
 	@Override
95
-	public Function<CodePosition, Expression> getDollar() {
94
+	public DollarEvaluator getDollar() {
96 95
 		return outer.getDollar();
97 96
 	}
98 97
 	
99 98
 	@Override
100
-	public IPartialExpression getOuterInstance(CodePosition position) {
99
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
101 100
 		return outer.getOuterInstance(position);
102 101
 	}
103 102
 

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java View File

@@ -6,13 +6,12 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14 14
 import org.openzen.zenscript.codemodel.GenericMapper;
15
-import org.openzen.zenscript.codemodel.expression.Expression;
16 15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
17 16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18 17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -62,7 +61,7 @@ public class FunctionScope extends StatementScope {
62 61
 	}
63 62
 
64 63
 	@Override
65
-	public IPartialExpression get(CodePosition position, GenericName name) {
64
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
66 65
 		IPartialExpression fromSuper = super.get(position, name);
67 66
 		if (fromSuper != null)
68 67
 			return fromSuper;
@@ -110,7 +109,7 @@ public class FunctionScope extends StatementScope {
110 109
 	}
111 110
 
112 111
 	@Override
113
-	public Function<CodePosition, Expression> getDollar() {
112
+	public DollarEvaluator getDollar() {
114 113
 		for (FunctionParameter parameter : header.parameters)
115 114
 			if (parameter.name.equals("$"))
116 115
 				return position -> new GetFunctionParameterExpression(position, parameter);
@@ -119,7 +118,7 @@ public class FunctionScope extends StatementScope {
119 118
 	}
120 119
 	
121 120
 	@Override
122
-	public IPartialExpression getOuterInstance(CodePosition position) {
121
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
123 122
 		return outer.getOuterInstance(position);
124 123
 	}
125 124
 

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java View File

@@ -8,12 +8,11 @@ package org.openzen.zenscript.codemodel.scope;
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11
-import java.util.function.Function;
12 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13 13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
15 15
 import org.openzen.zenscript.codemodel.GenericMapper;
16
-import org.openzen.zenscript.codemodel.expression.Expression;
17 16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18 17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
@@ -47,7 +46,7 @@ public class GenericFunctionScope extends BaseScope {
47 46
 	}
48 47
 
49 48
 	@Override
50
-	public IPartialExpression get(CodePosition position, GenericName name) {
49
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
51 50
 		if (parameters.containsKey(name.name) && name.hasNoArguments())
52 51
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)), name.arguments);
53 52
 		
@@ -83,12 +82,12 @@ public class GenericFunctionScope extends BaseScope {
83 82
 	}
84 83
 
85 84
 	@Override
86
-	public Function<CodePosition, Expression> getDollar() {
85
+	public DollarEvaluator getDollar() {
87 86
 		return outer.getDollar();
88 87
 	}
89 88
 	
90 89
 	@Override
91
-	public IPartialExpression getOuterInstance(CodePosition position) {
90
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
92 91
 		return outer.getOuterInstance(position);
93 92
 	}
94 93
 

+ 3
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java View File

@@ -6,12 +6,11 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
17 16
 import org.openzen.zenscript.codemodel.type.GenericName;
@@ -38,7 +37,7 @@ public class GlobalScriptScope extends StatementScope {
38 37
 	}
39 38
 	
40 39
 	@Override
41
-	public IPartialExpression get(CodePosition position, GenericName name) {
40
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
42 41
 		IPartialExpression result = super.get(position, name);
43 42
 		if (result != null)
44 43
 			return result;
@@ -72,7 +71,7 @@ public class GlobalScriptScope extends StatementScope {
72 71
 	}
73 72
 
74 73
 	@Override
75
-	public Function<CodePosition, Expression> getDollar() {
74
+	public DollarEvaluator getDollar() {
76 75
 		return null; // script arguments?
77 76
 	}
78 77
 

+ 3
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java View File

@@ -6,12 +6,11 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15 14
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
16 15
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
17 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -49,7 +48,7 @@ public class ImplementationScope extends BaseScope {
49 48
 	}
50 49
 
51 50
 	@Override
52
-	public IPartialExpression get(CodePosition position, GenericName name) {
51
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
53 52
 		if (members.hasInnerType(name.name))
54 53
 			return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
55 54
 		if (members.hasMember(name.name))
@@ -92,7 +91,7 @@ public class ImplementationScope extends BaseScope {
92 91
 	}
93 92
 
94 93
 	@Override
95
-	public Function<CodePosition, Expression> getDollar() {
94
+	public DollarEvaluator getDollar() {
96 95
 		return outer.getDollar();
97 96
 	}
98 97
 

+ 5
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java View File

@@ -6,13 +6,12 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14 14
 import org.openzen.zenscript.codemodel.GenericMapper;
15
-import org.openzen.zenscript.codemodel.expression.Expression;
16 15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
17 16
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
18 17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -45,7 +44,7 @@ public class LambdaScope extends StatementScope {
45 44
 	}
46 45
 	
47 46
 	@Override
48
-	public IPartialExpression get(CodePosition position, GenericName name) {
47
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
49 48
 		IPartialExpression outer = this.outer.get(position, name);
50 49
 		if (outer == null) {
51 50
 			if (name.hasNoArguments()) {
@@ -87,8 +86,8 @@ public class LambdaScope extends StatementScope {
87 86
 	}
88 87
 
89 88
 	@Override
90
-	public Function<CodePosition, Expression> getDollar() {
91
-		Function<CodePosition, Expression> outerDollar = outer.getDollar();
89
+	public DollarEvaluator getDollar() {
90
+		DollarEvaluator outerDollar = outer.getDollar();
92 91
 		if (outerDollar == null)
93 92
 			return null;
94 93
 		
@@ -96,7 +95,7 @@ public class LambdaScope extends StatementScope {
96 95
 	}
97 96
 	
98 97
 	@Override
99
-	public IPartialExpression getOuterInstance(CodePosition position) {
98
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
100 99
 		return outer.getOuterInstance(position);
101 100
 	}
102 101
 

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java View File

@@ -6,12 +6,11 @@
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
17 16
 import org.openzen.zenscript.codemodel.type.GenericName;
@@ -40,7 +39,7 @@ public class LoopScope extends StatementScope {
40 39
 	}
41 40
 
42 41
 	@Override
43
-	public IPartialExpression get(CodePosition position, GenericName name) {
42
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
44 43
 		IPartialExpression result = super.get(position, name);
45 44
 		if (result != null)
46 45
 			return result;
@@ -80,12 +79,12 @@ public class LoopScope extends StatementScope {
80 79
 	}
81 80
 
82 81
 	@Override
83
-	public Function<CodePosition, Expression> getDollar() {
82
+	public DollarEvaluator getDollar() {
84 83
 		return outer.getDollar();
85 84
 	}
86 85
 	
87 86
 	@Override
88
-	public IPartialExpression getOuterInstance(CodePosition position) {
87
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
89 88
 		return outer.getOuterInstance(position);
90 89
 	}
91 90
 

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.codemodel.scope;
8 8
 import java.util.HashMap;
9 9
 import java.util.Map;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 14
 import org.openzen.zenscript.codemodel.statement.VarStatement;
@@ -25,7 +26,7 @@ public abstract class StatementScope extends BaseScope {
25 26
 	}
26 27
 	
27 28
 	@Override
28
-	public IPartialExpression get(CodePosition position, GenericName name) {
29
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
29 30
 		if (variables.containsKey(name.name) && name.hasNoArguments())
30 31
 			return new GetLocalVariableExpression(position, variables.get(name.name));
31 32
 		

+ 5
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/IfStatement.java View File

@@ -77,6 +77,10 @@ public class IfStatement extends Statement {
77 77
 
78 78
 	@Override
79 79
 	public Statement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
80
-		return new IfStatement(position, condition.normalize(scope), onThen.normalize(scope, modified), onElse == null ? null : onElse.normalize(scope, modified));
80
+		return new IfStatement(
81
+				position,
82
+				condition.normalize(scope),
83
+				onThen.normalize(scope, modified),
84
+				onElse == null ? null : onElse.normalize(scope, modified));
81 85
 	}
82 86
 }

+ 6
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java View File

@@ -21,14 +21,16 @@ public class VarStatement extends Statement {
21 21
 	public final String name;
22 22
 	public final StoredType type;
23 23
 	public final Expression initializer;
24
+	public final VariableID variable;
24 25
 	public final boolean isFinal;
25 26
 	
26
-	public VarStatement(CodePosition position, String name, StoredType type, Expression initializer, boolean isFinal) {
27
+	public VarStatement(CodePosition position, VariableID variable, String name, StoredType type, Expression initializer, boolean isFinal) {
27 28
 		super(position, initializer == null ? null : initializer.thrownType);
28 29
 		
29 30
 		this.name = name;
30 31
 		this.type = type;
31 32
 		this.initializer = initializer;
33
+		this.variable = variable;
32 34
 		this.isFinal = isFinal;
33 35
 	}
34 36
 
@@ -50,17 +52,17 @@ public class VarStatement extends Statement {
50 52
 	@Override
51 53
 	public VarStatement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
52 54
 		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
53
-		return tInitializer == initializer ? this : new VarStatement(position, name, type, tInitializer, isFinal);
55
+		return tInitializer == initializer ? this : new VarStatement(position, variable, name, type, tInitializer, isFinal);
54 56
 	}
55 57
 
56 58
 	@Override
57 59
 	public VarStatement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
58 60
 		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
59
-		return tInitializer == initializer ? this : new VarStatement(position, name, type, tInitializer, isFinal);
61
+		return tInitializer == initializer ? this : new VarStatement(position, variable, name, type, tInitializer, isFinal);
60 62
 	}
61 63
 
62 64
 	@Override
63 65
 	public VarStatement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
64
-		return new VarStatement(position, name, type.getNormalized(), initializer == null ? null : initializer.normalize(scope), isFinal);
66
+		return new VarStatement(position, variable, name, type.getNormalized(), initializer == null ? null : initializer.normalize(scope), isFinal);
65 67
 	}
66 68
 }

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java View File

@@ -11,6 +11,8 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.FunctionParameter;
12 12
 import org.openzen.zenscript.codemodel.GenericMapper;
13 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
15
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
14 16
 
15 17
 /**
16 18
  *
@@ -107,7 +109,27 @@ public class FunctionTypeID implements TypeID {
107 109
 	
108 110
 	@Override
109 111
 	public String toString() {
112
+		return toString(null);
113
+	}
114
+	
115
+	@Override
116
+	public String toString(StorageTag storage) {
110 117
 		StringBuilder result = new StringBuilder();
118
+		result.append("function");
119
+		if (header.typeParameters.length > 0) {
120
+			result.append('<');
121
+			for (int i = 0; i < header.typeParameters.length; i++) {
122
+				if (i > 0)
123
+					result.append(", ");
124
+				
125
+				result.append(header.typeParameters[i].toString());
126
+			}
127
+			result.append('>');
128
+		}
129
+		if (storage != null && storage != ValueStorageTag.INSTANCE) {
130
+			result.append('`');
131
+			result.append(storage);
132
+		}
111 133
 		result.append('(');
112 134
 		for (int i = 0; i < header.parameters.length; i++) {
113 135
 			if (i > 0)

+ 5
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java View File

@@ -10,8 +10,6 @@ import org.openzen.zencode.shared.CodePosition;
10 10
 import org.openzen.zencode.shared.CompileExceptionCode;
11 11
 import org.openzen.zenscript.codemodel.GenericMapper;
12 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
-import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
-import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
15 13
 
16 14
 /**
17 15
  *
@@ -67,4 +65,9 @@ public class InvalidTypeID implements TypeID {
67 65
 	public <C, R, E extends Exception> R accept(C context, TypeVisitorWithContext<C, R, E> visitor) throws E {
68 66
 		return visitor.visitInvalid(context, this);
69 67
 	}
68
+	
69
+	@Override
70
+	public String toString() {
71
+		return "invalid";
72
+	}
70 73
 }

+ 14
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java View File

@@ -9,6 +9,7 @@ import java.util.List;
9 9
 import java.util.Objects;
10 10
 import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12 13
 
13 14
 /**
14 15
  *
@@ -140,4 +141,17 @@ public class ModifiedTypeID implements TypeID {
140 141
 			result.append("?");
141 142
 		return result.toString();
142 143
 	}
144
+	
145
+	@Override
146
+	public String toString(StorageTag storage) {
147
+		StringBuilder result = new StringBuilder();
148
+		if ((modifiers & MODIFIER_IMMUTABLE) > 0)
149
+			result.append("immutable ");
150
+		if ((modifiers & MODIFIER_CONST) > 0)
151
+			result.append("const ");
152
+		result.append(baseType.toString(storage));
153
+		if ((modifiers & MODIFIER_OPTIONAL) > 0)
154
+			result.append("?");
155
+		return result.toString();
156
+	}
143 157
 }

+ 1
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java View File

@@ -122,10 +122,7 @@ public class StoredType {
122 122
 	
123 123
 	@Override
124 124
 	public String toString() {
125
-		if (storage == ValueStorageTag.INSTANCE)
126
-			return type.toString();
127
-		
128
-		return type.toString() + "`" + storage.toString();
125
+		return type.toString(storage);
129 126
 	}
130 127
 	
131 128
 	public static class MatchingTypeVisitor implements TypeVisitor<Boolean> {

+ 8
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java View File

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.GenericMapper;
11 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12 12
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13 13
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
14 15
 
15 16
 /**
16 17
  *
@@ -80,4 +81,11 @@ public interface TypeID {
80 81
 	default boolean isEnum() {
81 82
 		return false;
82 83
 	}
84
+	
85
+	default String toString(StorageTag storage) {
86
+		if (storage == ValueStorageTag.INSTANCE)
87
+			return toString();
88
+		
89
+		return toString() + "`" + storage.toString();
90
+	}
83 91
 }

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java View File

@@ -60,6 +60,11 @@ public class TypeMatcher implements TypeVisitorWithContext<TypeMatcher.Matching,
60 60
 			return false;
61 61
 		}
62 62
 	}
63
+	
64
+	@Override
65
+	public Boolean visitInvalid(Matching context, InvalidTypeID invalid) {
66
+		return false;
67
+	}
63 68
 
64 69
 	@Override
65 70
 	public Boolean visitIterator(Matching context, IteratorTypeID iterator) {

+ 8
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java View File

@@ -6,7 +6,6 @@
6 6
 package org.openzen.zenscript.codemodel.type.member;
7 7
 
8 8
 import java.util.Collections;
9
-import java.util.HashMap;
10 9
 import java.util.List;
11 10
 import java.util.Map;
12 11
 import org.openzen.zencode.shared.CodePosition;
@@ -68,6 +67,7 @@ import org.openzen.zenscript.codemodel.Module;
68 67
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
69 68
 import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
70 69
 import org.openzen.zenscript.codemodel.member.IteratorMember;
70
+import org.openzen.zenscript.codemodel.type.InvalidTypeID;
71 71
 import org.openzen.zenscript.codemodel.type.StoredType;
72 72
 import org.openzen.zenscript.codemodel.type.StringTypeID;
73 73
 import org.openzen.zenscript.codemodel.type.TypeVisitorWithContext;
@@ -413,6 +413,11 @@ public class TypeMemberBuilder implements TypeVisitorWithContext<Void, Void, Run
413 413
 		return null;
414 414
 	}
415 415
 	
416
+	@Override
417
+	public Void visitInvalid(Void context, InvalidTypeID invalid) {
418
+		return null;
419
+	}
420
+	
416 421
 	@Override
417 422
 	public Void visitIterator(Void context, IteratorTypeID iterator) {
418 423
 		return null;
@@ -766,6 +771,7 @@ public class TypeMemberBuilder implements TypeVisitorWithContext<Void, Void, Run
766 771
 		dec(builtin, INT_INC, INT);
767 772
 
768 773
 		add(builtin, INT_ADD_INT, INT, INT);
774
+		add(builtin, LONG_ADD_LONG, USIZE, LONG, INT_TO_LONG);
769 775
 		add(builtin, LONG_ADD_LONG, LONG, LONG, INT_TO_LONG);
770 776
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, INT_TO_FLOAT);
771 777
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, INT_TO_DOUBLE);
@@ -846,6 +852,7 @@ public class TypeMemberBuilder implements TypeVisitorWithContext<Void, Void, Run
846 852
 		dec(builtin, UINT_INC, INT);
847 853
 
848 854
 		add(builtin, UINT_ADD_UINT, UINT, UINT);
855
+		add(builtin, ULONG_ADD_ULONG, USIZE, ULONG, UINT_TO_ULONG);
849 856
 		add(builtin, ULONG_ADD_ULONG, ULONG, ULONG, UINT_TO_ULONG);
850 857
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, UINT_TO_FLOAT);
851 858
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, UINT_TO_DOUBLE);

+ 93
- 125
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberGroup.java View File

@@ -32,7 +32,6 @@ import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
32 32
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
33 33
 import org.openzen.zenscript.codemodel.member.ref.SetterMemberRef;
34 34
 import org.openzen.zenscript.codemodel.scope.TypeScope;
35
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
36 35
 import org.openzen.zenscript.codemodel.type.StoredType;
37 36
 import org.openzen.zenscript.codemodel.type.TypeID;
38 37
 
@@ -160,116 +159,100 @@ public class TypeMemberGroup {
160 159
 		methods.add(new TypeMember<>(priority, method));
161 160
 	}
162 161
 	
163
-	public Expression getter(CodePosition position, TypeScope scope, Expression target, boolean allowStaticUsage) {
164
-		try {
165
-			if (getter != null) {
166
-				if (getter.member.isStatic()) {
167
-					if (!allowStaticUsage)
168
-						return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
162
+	public Expression getter(CodePosition position, TypeScope scope, Expression target, boolean allowStaticUsage) throws CompileException {
163
+		if (getter != null) {
164
+			if (getter.member.isStatic()) {
165
+				if (!allowStaticUsage)
166
+					return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
169 167
 
170
-					return getter.member.getStatic(position);
171
-				}
172
-
173
-				scope.getPreparer().prepare(getter.member.member);
174
-				return getter.member.get(position, target);
175
-			} else if (field != null) {
176
-				if (field.member.isStatic()) {
177
-					if (!allowStaticUsage)
178
-						return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
168
+				return getter.member.getStatic(position);
169
+			}
179 170
 
180
-					return new GetStaticFieldExpression(position, field.member);
181
-				}
171
+			scope.getPreparer().prepare(getter.member.member);
172
+			return getter.member.get(position, target);
173
+		} else if (field != null) {
174
+			if (field.member.isStatic()) {
175
+				if (!allowStaticUsage)
176
+					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
182 177
 
183
-				scope.getPreparer().prepare(field.member.member);
184
-				return new GetFieldExpression(position, target, field.member);
185
-			} else {
186
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_GETTER, "Value is not a property");
178
+				return new GetStaticFieldExpression(position, field.member);
187 179
 			}
188
-		} catch (CompileException ex) {
189
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
180
+
181
+			scope.getPreparer().prepare(field.member.member);
182
+			return new GetFieldExpression(position, target, field.member);
183
+		} else {
184
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_GETTER, "Value is not a property");
190 185
 		}
191 186
 	}
192 187
 	
193
-	public Expression setter(CodePosition position, TypeScope scope, Expression target, Expression value, boolean allowStaticUsage) {
194
-		try {
195
-			if (setter != null) {
196
-				if (setter.member.isStatic()) {
197
-					if (!allowStaticUsage)
198
-						return new InvalidExpression(position, setter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
199
-
200
-					scope.getPreparer().prepare(setter.member.member);
201
-					return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
202
-				}
188
+	public Expression setter(CodePosition position, TypeScope scope, Expression target, Expression value, boolean allowStaticUsage) throws CompileException {
189
+		if (setter != null) {
190
+			if (setter.member.isStatic()) {
191
+				if (!allowStaticUsage)
192
+					return new InvalidExpression(position, setter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
203 193
 
204 194
 				scope.getPreparer().prepare(setter.member.member);
205
-				return new SetterExpression(position, target, setter.member, value.castImplicit(position, scope, setter.member.getType()));
206
-			} else if (field != null) {
207
-				// TODO: perform proper checks on val fields
208
-				//if (field.isFinal)
209
-				//	throw new CompileException(position, "This field cannot be modified");
210
-				if (field.member.isStatic()) {
211
-					if (!allowStaticUsage)
212
-						return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
195
+				return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
196
+			}
213 197
 
214
-					scope.getPreparer().prepare(field.member.member);
215
-					return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
216
-				}
198
+			scope.getPreparer().prepare(setter.member.member);
199
+			return new SetterExpression(position, target, setter.member, value.castImplicit(position, scope, setter.member.getType()));
200
+		} else if (field != null) {
201
+			// TODO: perform proper checks on val fields
202
+			//if (field.isFinal)
203
+			//	throw new CompileException(position, "This field cannot be modified");
204
+			if (field.member.isStatic()) {
205
+				if (!allowStaticUsage)
206
+					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
217 207
 
218 208
 				scope.getPreparer().prepare(field.member.member);
219
-				return new SetFieldExpression(position, target, field.member, value.castImplicit(position, scope, field.member.getType()));
220
-			} else {
221
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_SETTER, "Value is not settable");
209
+				return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
222 210
 			}
223
-		} catch (CompileException ex) {
224
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
211
+
212
+			scope.getPreparer().prepare(field.member.member);
213
+			return new SetFieldExpression(position, target, field.member, value.castImplicit(position, scope, field.member.getType()));
214
+		} else {
215
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_SETTER, "Value is not settable");
225 216
 		}
226 217
 	}
227 218
 	
228
-	public Expression staticGetter(CodePosition position, TypeScope scope) {
229
-		try {
230
-			if (constant != null) {
231
-				return new ConstExpression(position, constant.member);
232
-			} else if (getter != null) {
233
-				if (!getter.member.isStatic())
234
-					return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
219
+	public Expression staticGetter(CodePosition position, TypeScope scope) throws CompileException {
220
+		if (constant != null) {
221
+			return new ConstExpression(position, constant.member);
222
+		} else if (getter != null) {
223
+			if (!getter.member.isStatic())
224
+				return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
235 225
 
236
-				scope.getPreparer().prepare(getter.member.member);
237
-				return getter.member.getStatic(position);
238
-			} else if (field != null) {
239
-				if (!field.member.isStatic())
240
-					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
226
+			scope.getPreparer().prepare(getter.member.member);
227
+			return getter.member.getStatic(position);
228
+		} else if (field != null) {
229
+			if (!field.member.isStatic())
230
+				return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
241 231
 
242
-				scope.getPreparer().prepare(field.member.member);
243
-				return new GetStaticFieldExpression(position, field.member);
244
-			} else {
245
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_GETTER, "Member is not gettable");
246
-			}
247
-		} catch (CompileException ex) {
248
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
232
+			scope.getPreparer().prepare(field.member.member);
233
+			return new GetStaticFieldExpression(position, field.member);
234
+		} else {
235
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_GETTER, "Member is not gettable");
249 236
 		}
250 237
 	}
251 238
 	
252
-	public Expression staticSetter(CodePosition position, TypeScope scope, Expression value) {
253
-		try {
254
-			if (getter != null) {
255
-				if (!getter.member.isStatic())
256
-					return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
239
+	public Expression staticSetter(CodePosition position, TypeScope scope, Expression value) throws CompileException {
240
+		if (getter != null) {
241
+			if (!getter.member.isStatic())
242
+				return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
257 243
 
258
-				scope.getPreparer().prepare(setter.member.member);
259
-				return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
260
-			} else if (field != null) {
261
-				//if (field.member.isFinal)
262
-				//	throw new CompileException(position, CompileExceptionCode.MEMBER_IS_FINAL, "This field cannot be modified");
263
-				if (!field.member.isStatic())
264
-					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
244
+			scope.getPreparer().prepare(setter.member.member);
245
+			return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
246
+		} else if (field != null) {
247
+			//if (field.member.isFinal)
248
+			//	throw new CompileException(position, CompileExceptionCode.MEMBER_IS_FINAL, "This field cannot be modified");
249
+			if (!field.member.isStatic())
250
+				return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
265 251
 
266
-				scope.getPreparer().prepare(field.member.member);
267
-				return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
268
-			} else {
269
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_SETTER, "Member is not settable");
270
-			}
271
-		} catch (CompileException ex) {
272
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
252
+			scope.getPreparer().prepare(field.member.member);
253
+			return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
254
+		} else {
255
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_SETTER, "Member is not settable");
273 256
 		}
274 257
 	}
275 258
 	
@@ -302,35 +285,27 @@ public class TypeMemberGroup {
302 285
 		return result;
303 286
 	}
304 287
 	
305
-	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) {
306
-		try {
307
-			FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
308
-			FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
309
-			for (int i = 0; i < arguments.arguments.length; i++) {
310
-				arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
311
-			}
312
-
313
-			scope.getPreparer().prepare(method.getTarget());
314
-			return method.call(position, target, instancedHeader, arguments, scope);
315
-		} catch (CompileException ex) {
316
-			return new InvalidExpression(position, ex.code, ex.getMessage());
288
+	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) throws CompileException {
289
+		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
290
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
291
+		for (int i = 0; i < arguments.arguments.length; i++) {
292
+			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
317 293
 		}
294
+
295
+		scope.getPreparer().prepare(method.getTarget());
296
+		return method.call(position, target, instancedHeader, arguments, scope);
318 297
 	}
319 298
 	
320
-	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) {
299
+	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) throws CompileException {
321 300
 		if (methods.isEmpty())
322
-			return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "There is no such operator");
301
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "There is no such operator");
323 302
 		
324 303
 		FunctionalMemberRef method = methods.get(0).member;
325 304
 		if (!method.isOperator())
326
-			return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member is not an operator");
305
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member is not an operator");
327 306
 		
328
-		try {
329
-			scope.getPreparer().prepare(method.getTarget());
330
-			return new PostCallExpression(position, target, method, method.getHeader());
331
-		} catch (CompileException ex) {
332
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
333
-		}
307
+		scope.getPreparer().prepare(method.getTarget());
308
+		return new PostCallExpression(position, target, method, method.getHeader());
334 309
 	}
335 310
 	
336 311
 	public Expression callWithComparator(
@@ -338,24 +313,17 @@ public class TypeMemberGroup {
338 313
 			TypeScope scope,
339 314
 			Expression target,
340 315
 			CallArguments arguments,
341
-			CompareType compareType) {
342
-		try {
343
-			FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
344
-			FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
345
-			return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
346
-		} catch (CompileException ex) {
347
-			return new InvalidExpression(position, ex.code, ex.getMessage());
348
-		}
316
+			CompareType compareType) throws CompileException
317
+	{
318
+		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
319
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
320
+		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
349 321
 	}
350 322
 	
351
-	public Expression callStatic(CodePosition position, TypeID target, TypeScope scope, CallArguments arguments) {
352
-		try {
353
-			FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
354
-			FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
355
-			return method.callStatic(position, target, instancedHeader, arguments, scope);
356
-		} catch (CompileException ex) {
357
-			return new InvalidExpression(position, ex.code, ex.getMessage());
358
-		}
323
+	public Expression callStatic(CodePosition position, TypeID target, TypeScope scope, CallArguments arguments) throws CompileException {
324
+		FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
325
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
326
+		return method.callStatic(position, target, instancedHeader, arguments, scope);
359 327
 	}
360 328
 	
361 329
 	public FunctionalMemberRef selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) throws CompileException {

+ 12
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java View File

@@ -49,6 +49,7 @@ import org.openzen.zenscript.codemodel.type.GenericName;
49 49
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
50 50
 import org.openzen.zenscript.codemodel.scope.TypeScope;
51 51
 import org.openzen.zenscript.codemodel.type.StoredType;
52
+import org.openzen.zenscript.codemodel.type.StringTypeID;
52 53
 import org.openzen.zenscript.codemodel.type.TypeID;
53 54
 
54 55
 /**
@@ -352,7 +353,7 @@ public final class TypeMembers {
352 353
 		return variantOptions.get(name);
353 354
 	}
354 355
 	
355
-	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) {
356
+	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) throws CompileException {
356 357
 		if (operator == CompareType.EQ) {
357 358
 			TypeMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
358 359
 			for (TypeMember<FunctionalMemberRef> member : equal.getMethodMembers()) {
@@ -372,7 +373,7 @@ public final class TypeMembers {
372 373
 		return compare.callWithComparator(position, scope, left, new CallArguments(right), operator);
373 374
 	}
374 375
 	
375
-	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) {
376
+	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) throws CompileException {
376 377
 		TypeMemberGroup members = getOrCreateGroup(operator);
377 378
 		return members.call(position, scope, value, new CallArguments(Expression.NONE), false);
378 379
 	}
@@ -458,13 +459,19 @@ public final class TypeMembers {
458 459
 	}
459 460
 	
460 461
 	private Expression castEquivalent(CodePosition position, Expression value, StoredType toType) {
461
-		if (toType == value.type)
462
+		if (toType.equals(value.type))
462 463
 			return value;
463 464
 		
465
+		if (!(toType.type instanceof StringTypeID))
466
+			System.out.println(position + ": " + value.type.storage + " -> " + toType.storage);
467
+		
464 468
 		return new StorageCastExpression(position, value, toType);
465 469
 	}
466 470
 	
467 471
 	public Expression castImplicit(CodePosition position, Expression value, StoredType toType, boolean implicit) {
472
+		if (toType == null)
473
+			throw new NullPointerException();
474
+		
468 475
 		toType = toType.getNormalized();
469 476
 		if (toType.type == BasicTypeID.UNDETERMINED)
470 477
 			return value;
@@ -500,8 +507,8 @@ public final class TypeMembers {
500 507
 			return castImplicit(position, value, toType, false);
501 508
 		
502 509
 		for (TypeMember<CasterMemberRef> caster : casters)
503
-			if (toType == caster.member.toType)
504
-				return caster.member.cast(position, value, false);
510
+			if (areEquivalent(caster.member.toType, toType))
511
+				return castEquivalent(position, caster.member.cast(position, value, false), toType);
505 512
 		
506 513
 		return new InvalidExpression(position, toType, CompileExceptionCode.INVALID_CAST, "Cannot cast " + toString() + " to " + toType + ", even explicitly");
507 514
 	}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageTag.java View File

@@ -31,7 +31,7 @@ public class SharedStorageTag implements StorageTag {
31 31
 
32 32
 	@Override
33 33
 	public boolean canCastFrom(StorageTag other) {
34
-		return other == this || other == UniqueStorageTag.INSTANCE;
34
+		return other == this || other == UniqueStorageTag.INSTANCE || other == StaticStorageTag.INSTANCE;
35 35
 	}
36 36
 
37 37
 	@Override

+ 4
- 3
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

@@ -88,12 +88,13 @@ public class SemanticModule {
88 88
 		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(compilationUnit.globalTypeRegistry, annotations, storageTypes, rootPackage, null, globals);
89 89
 		AnnotationProcessor annotationProcessor = new AnnotationProcessor(context, expansions);
90 90
 		List<ScriptBlock> processedScripts = new ArrayList<>();
91
+		FileScope fileScope = new FileScope(context, expansions, globals, member -> {});
92
+			
91 93
 		for (ScriptBlock block : scripts)
92
-			processedScripts.add(annotationProcessor.process(block));
94
+			processedScripts.add(annotationProcessor.process(block).normalize(fileScope));
95
+		
93 96
 		for (HighLevelDefinition definition : definitions.getAll()) {
94 97
 			annotationProcessor.process(definition);
95
-			
96
-			FileScope fileScope = new FileScope(context, expansions, globals, member -> {});
97 98
 			definition.normalize(fileScope);
98 99
 		}
99 100
 		

+ 5
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

@@ -1778,7 +1778,10 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1778 1778
 	@Override
1779 1779
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
1780 1780
 		final Label label = new Label();
1781
-		final JavaLocalVariableInfo tag = expression.variable.getTag(JavaLocalVariableInfo.class);
1781
+		final JavaLocalVariableInfo tag = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
1782
+		if (tag == null)
1783
+			throw new RuntimeException("Missing tag @ " + expression.position);
1784
+		
1782 1785
 		tag.end = label;
1783 1786
 		javaWriter.load(tag.type, tag.local);
1784 1787
 		javaWriter.label(label);
@@ -2242,7 +2245,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2242 2245
 		expression.value.accept(this);
2243 2246
 		Label label = new Label();
2244 2247
 		javaWriter.label(label);
2245
-		final JavaLocalVariableInfo tag = expression.variable.getTag(JavaLocalVariableInfo.class);
2248
+		final JavaLocalVariableInfo tag = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
2246 2249
 		tag.end = label;
2247 2250
 
2248 2251
 		javaWriter.store(tag.type, tag.local);

+ 4
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java View File

@@ -29,7 +29,7 @@ public class JavaForeachWriter {
29 29
 		javaWriter.swap();
30 30
 		javaWriter.getField("zsynthetic/IntRange", "from", "I");
31 31
 
32
-		final int z = variables[0].getTag(JavaLocalVariableInfo.class).local;
32
+		final int z = variables[0].variable.getTag(JavaLocalVariableInfo.class).local;
33 33
 		javaWriter.storeInt(z);
34 34
 		javaWriter.label(startLabel);
35 35
 		javaWriter.dup();
@@ -41,17 +41,17 @@ public class JavaForeachWriter {
41 41
 	}
42 42
 
43 43
 	public void visitArrayValueIterator() {
44
-		handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
44
+		handleArray(javaWriter.local(int.class), variables[0].variable.getTag(JavaLocalVariableInfo.class));
45 45
 	}
46 46
 
47 47
 	public void visitArrayKeyValueIterator() {
48
-		handleArray(variables[0].getTag(JavaLocalVariableInfo.class).local, variables[1].getTag(JavaLocalVariableInfo.class));
48
+		handleArray(variables[0].variable.getTag(JavaLocalVariableInfo.class).local, variables[1].variable.getTag(JavaLocalVariableInfo.class));
49 49
 	}
50 50
 
51 51
 	public void visitStringCharacterIterator() {
52 52
 		//TODO UNTESTED!
53 53
 		javaWriter.invokeSpecial("java/lang/String", "toCharArray()", "()[C");
54
-		handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
54
+		handleArray(javaWriter.local(int.class), variables[0].variable.getTag(JavaLocalVariableInfo.class));
55 55
 	}
56 56
 
57 57
 	private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java View File

@@ -221,7 +221,7 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
221 221
 	
222 222
 	@Override
223 223
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
224
-		javaWriter.idec(expression.variable.getTag(JavaLocalVariableInfo.class).local);
224
+		javaWriter.idec(expression.variable.variable.getTag(JavaLocalVariableInfo.class).local);
225 225
 		return null;
226 226
 	}
227 227
 

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java View File

@@ -224,7 +224,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
224 224
 
225 225
 	@Override
226 226
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
227
-		JavaLocalVariableInfo localVariable = expression.variable.getTag(JavaLocalVariableInfo.class);
227
+		JavaLocalVariableInfo localVariable = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
228 228
 		javaWriter.iinc(localVariable.local);
229 229
 		javaWriter.load(localVariable);
230 230
 		return null;

+ 2
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java View File

@@ -103,7 +103,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
103 103
             final Label variableStart = new Label();
104 104
             final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
105 105
             info.end = end;
106
-            variable.setTag(JavaLocalVariableInfo.class, info);
106
+            variable.variable.setTag(JavaLocalVariableInfo.class, info);
107 107
             javaWriter.addVariableInfo(info);
108 108
         }
109 109
 
@@ -311,7 +311,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
311 311
 		final Label variableStart = new Label();
312 312
 		javaWriter.label(variableStart);
313 313
 		final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
314
-		statement.setTag(JavaLocalVariableInfo.class, info);
314
+		statement.variable.setTag(JavaLocalVariableInfo.class, info);
315 315
 		javaWriter.addVariableInfo(info);
316 316
 		return false;
317 317
 	}

+ 0
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java View File

@@ -2,7 +2,6 @@ package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3 3
 import org.objectweb.asm.*;
4 4
 
5
-import java.lang.reflect.Field;
6 5
 import java.util.ArrayList;
7 6
 import java.util.HashMap;
8 7
 import java.util.List;

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java View File

@@ -145,7 +145,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
145 145
 		final JavaWriter writer = new JavaWriter(outerWriter, true, method, definition, signature, null);
146 146
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, writer);
147 147
         statementVisitor.start();
148
-		boolean returns = definition.statement.accept(statementVisitor);
148
+		boolean returns = definition.caller.body.accept(statementVisitor);
149 149
 		if (!returns) {
150 150
 			StoredType type = definition.header.getReturnType();
151 151
 			if (CompilerUtils.isPrimitive(type.type))

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java View File

@@ -1695,7 +1695,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1695 1695
 								.append(newArray(type.elementType, size))
1696 1696
 								.append(";")
1697 1697
 								.toString());
1698
-					VarStatement tempI = new VarStatement(expression.position, scope.createTempVariable(), BasicTypeID.INT.stored, null, true);
1698
+					VarStatement tempI = new VarStatement(expression.position, new VariableID(), scope.createTempVariable(), BasicTypeID.INT.stored, null, true);
1699 1699
 					target.writeLine(new StringBuilder()
1700 1700
 								.append("for (int ")
1701 1701
 								.append(tempI.name)

+ 2
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceStatementScope.java View File

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
13 13
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
14 14
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15 15
 import org.openzen.zenscript.codemodel.statement.VarStatement;
16
+import org.openzen.zenscript.codemodel.statement.VariableID;
16 17
 import org.openzen.zenscript.codemodel.type.StoredType;
17 18
 import org.openzen.zenscript.codemodel.type.TypeID;
18 19
 import org.openzen.zenscript.formattershared.ExpressionString;
@@ -115,7 +116,7 @@ public class JavaSourceStatementScope {
115 116
 		if (!shouldHoist)
116 117
 			return expression;
117 118
 		
118
-		VarStatement temp = new VarStatement(expression.position, createTempVariable(), expression.type, expression, true);
119
+		VarStatement temp = new VarStatement(expression.position, new VariableID(), createTempVariable(), expression.type, expression, true);
119 120
 		new JavaSourceStatementFormatter(this).formatVar(target, temp);
120 121
 		return new GetLocalVariableExpression(expression.position, temp);
121 122
 	}

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java View File

@@ -78,7 +78,7 @@ public class ParsedFunction extends ParsedDefinition {
78 78
 		compiled.setCode(body.compile(innerScope, compiled.header));
79 79
 		
80 80
 		if (compiled.header.getReturnType().isBasic(BasicTypeID.UNDETERMINED))
81
-			compiled.header.setReturnType(compiled.statement.getReturnType());
81
+			compiled.header.setReturnType(compiled.caller.body.getReturnType());
82 82
 	}
83 83
 
84 84
 	@Override

+ 7
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionParameter.java View File

@@ -1,8 +1,10 @@
1 1
 package org.openzen.zenscript.parser.definitions;
2 2
 
3
+import org.openzen.zencode.shared.CompileException;
3 4
 import org.openzen.zenscript.codemodel.FunctionParameter;
4 5
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
5 6
 import org.openzen.zenscript.codemodel.expression.Expression;
7
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
6 8
 import org.openzen.zenscript.codemodel.scope.BaseScope;
7 9
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
8 10
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -43,7 +45,11 @@ public class ParsedFunctionParameter {
43 45
 	
44 46
 	public void compileInitializer(BaseScope scope, PrecompilationState state) {
45 47
 		if (defaultValue != null) {
46
-			compiled.defaultValue = defaultValue.compile(new ExpressionScope(scope, compiled.type)).eval();
48
+			try {
49
+				compiled.defaultValue = defaultValue.compile(new ExpressionScope(scope, compiled.type)).eval();
50
+			} catch (CompileException ex) {
51
+				compiled.defaultValue = new InvalidExpression(compiled.type, ex);
52
+			}
47 53
 		}
48 54
 	}
49 55
 }

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java View File

@@ -39,6 +39,7 @@ public class ParsedVariant extends BaseParsedDefinition {
39 39
 		
40 40
 		int ordinal = 0;
41 41
 		while (!tokens.isNext(ZSTokenType.T_ACLOSE) && !tokens.isNext(ZSTokenType.T_SEMICOLON)) {
42
+			CodePosition optionPosition = tokens.getPosition();
42 43
 			String optionName = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
43 44
 			List<IParsedType> types = new ArrayList<>();
44 45
 			if (tokens.optional(ZSTokenType.T_BROPEN) != null) {
@@ -48,7 +49,7 @@ public class ParsedVariant extends BaseParsedDefinition {
48 49
 				}
49 50
 				tokens.required(ZSTokenType.T_BRCLOSE, ") expected");
50 51
 			}
51
-			result.addVariant(new ParsedVariantOption(optionName, ordinal++, types));
52
+			result.addVariant(new ParsedVariantOption(optionPosition, optionName, ordinal++, types));
52 53
 			if (tokens.optional(ZSTokenType.T_COMMA) == null)
53 54
 				break;
54 55
 		}

+ 5
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariantOption.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.definitions;
7 7
 
8 8
 import java.util.List;
9
+import org.openzen.zencode.shared.CodePosition;
9 10
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10 11
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11 12
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -16,11 +17,13 @@ import org.openzen.zenscript.parser.type.IParsedType;
16 17
  * @author Hoofdgebruiker
17 18
  */
18 19
 public class ParsedVariantOption {
20
+	public final CodePosition position;
19 21
 	public final String name;
20 22
 	public final int ordinal;
21 23
 	public final List<IParsedType> types;
22 24
 	
23
-	public ParsedVariantOption(String name, int ordinal, List<IParsedType> types) {
25
+	public ParsedVariantOption(CodePosition position, String name, int ordinal, List<IParsedType> types) {
26
+		this.position = position;
24 27
 		this.name = name;
25 28
 		this.ordinal = ordinal;
26 29
 		this.types = types;
@@ -31,6 +34,6 @@ public class ParsedVariantOption {
31 34
 		for (int i = 0; i < cTypes.length; i++)
32 35
 			cTypes[i] = types.get(i).compile(context);
33 36
 		
34
-		return new VariantDefinition.Option(variant, name, ordinal, cTypes);
37
+		return new VariantDefinition.Option(position, variant, name, ordinal, cTypes);
35 38
 	}
36 39
 }

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedCallArguments.java View File

@@ -210,7 +210,7 @@ public class ParsedCallArguments {
210 210
 		return new CallArguments(typeArguments2, cArguments);
211 211
 	}
212 212
 	
213
-	private CallArguments compileCallNaive(CodePosition position, ExpressionScope scope) {
213
+	private CallArguments compileCallNaive(CodePosition position, ExpressionScope scope) throws CompileException {
214 214
 		Expression[] cArguments = new Expression[arguments.size()];
215 215
 		for (int i = 0; i < cArguments.length; i++) {
216 216
 			IPartialExpression cArgument = arguments.get(i).compile(scope);

+ 5
- 8
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java View File

@@ -5,14 +5,12 @@
5 5
  */
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8
-import java.util.function.Function;
9 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10 10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
-import org.openzen.zenscript.codemodel.expression.Expression;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
+import org.openzen.zenscript.codemodel.scope.BaseScope.DollarEvaluator;
14 13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 14
 
17 15
 /**
18 16
  *
@@ -24,12 +22,11 @@ public class ParsedDollarExpression extends ParsedExpression {
24 22
 	}
25 23
 
26 24
 	@Override
27
-	public IPartialExpression compile(ExpressionScope scope) {
28
-		Function<CodePosition, Expression> dollar = scope.getDollar();
25
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
26
+		DollarEvaluator dollar = scope.getDollar();
29 27
 		if (dollar == null)
30
-			return new InvalidExpression(
28
+			throw new CompileException(
31 29
 					position,
32
-					scope.hints.isEmpty() ? BasicTypeID.UNDETERMINED.stored : scope.hints.get(0),
33 30
 					CompileExceptionCode.NO_DOLLAR_HERE,
34 31
 					"No dollar expression available in this context");
35 32
 		

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java View File

@@ -577,9 +577,9 @@ public abstract class ParsedExpression {
577 577
 	 * @param scope
578 578
 	 * @return 
579 579
 	 */
580
-	public abstract IPartialExpression compile(ExpressionScope scope);
580
+	public abstract IPartialExpression compile(ExpressionScope scope) throws CompileException;
581 581
 
582
-	public Expression compileKey(ExpressionScope scope) {
582
+	public Expression compileKey(ExpressionScope scope) throws CompileException {
583 583
 		return compile(scope).eval();
584 584
 	}
585 585
 	

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAndAnd.java View File

@@ -7,10 +7,10 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zencode.shared.CompileExceptionCode;
11 12
 import org.openzen.zenscript.codemodel.expression.AndAndExpression;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
14 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16 16
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -34,13 +34,13 @@ public class ParsedExpressionAndAnd extends ParsedExpression {
34 34
 	}
35 35
 
36 36
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
37
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38 38
 		Expression left = this.left.compile(scope).eval();
39 39
 		Expression right = this.right.compile(scope).eval();
40 40
 		
41 41
 		StoredType resultType = scope.getTypeMembers(left.type).union(right.type);
42 42
 		if (resultType == null)
43
-			return new InvalidExpression(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + left.type + " and " + right.type);
43
+			throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + left.type + " and " + right.type);
44 44
 		
45 45
 		left = left.castImplicit(position, scope, resultType);
46 46
 		right = right.castImplicit(position, scope, resultType);

+ 9
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12 13
 import org.openzen.zenscript.codemodel.expression.ArrayExpression;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -32,7 +33,7 @@ public class ParsedExpressionArray extends ParsedExpression {
32 33
 	}
33 34
 
34 35
 	@Override
35
-	public IPartialExpression compile(ExpressionScope scope) {
36
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
36 37
 		StoredType asBaseType = null;
37 38
 		StoredType asType = null;
38 39
 		boolean couldHintType = false;
@@ -55,13 +56,17 @@ public class ParsedExpressionArray extends ParsedExpression {
55 56
 			for (int i = 0; i < contents.size(); i++)
56 57
 				cContents[i] = contents.get(i).compile(contentScope).eval().castImplicit(position, scope, asBaseType);
57 58
 		} else if (contents.isEmpty()) {
58
-			return new InvalidExpression(position, CompileExceptionCode.UNTYPED_EMPTY_ARRAY, "Empty array with unknown type");
59
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_ARRAY, "Empty array with unknown type");
59 60
 		} else {
60 61
 			ExpressionScope contentScope = scope.withoutHints();
61 62
 			StoredType resultType = null;
62 63
 			for (int i = 0; i < contents.size(); i++) {
63 64
 				cContents[i] = contents.get(i).compileKey(contentScope).eval();
64
-				resultType = resultType == null ? cContents[i].type : scope.getTypeMembers(resultType).union(cContents[i].type);
65
+				StoredType joinedType = resultType == null ? cContents[i].type : scope.getTypeMembers(resultType).union(cContents[i].type);
66
+				if (joinedType == null)
67
+					throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "Could not combine " + resultType + " with " + cContents[i].type);
68
+				
69
+				resultType = joinedType;
65 70
 			}
66 71
 			for (int i = 0; i < contents.size(); i++)
67 72
 				cContents[i] = cContents[i].castImplicit(position, scope, resultType);
@@ -71,7 +76,7 @@ public class ParsedExpressionArray extends ParsedExpression {
71 76
 	}
72 77
 
73 78
 	@Override
74
-	public Expression compileKey(ExpressionScope scope) {
79
+	public Expression compileKey(ExpressionScope scope) throws CompileException {
75 80
 		if (contents.size() == 1) {
76 81
 			return contents.get(0).compile(scope).eval();
77 82
 		} else {

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAssign.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
@@ -29,7 +30,7 @@ public class ParsedExpressionAssign extends ParsedExpression {
29 30
 	}
30 31
 
31 32
 	@Override
32
-	public IPartialExpression compile(ExpressionScope scope) {
33
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
33 34
 		IPartialExpression cLeft = left.compile(scope);
34 35
 		List<StoredType> resultHints = cLeft.getAssignHints();
35 36
 		

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBinary.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.OperatorType;
11 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -32,7 +33,7 @@ public class ParsedExpressionBinary extends ParsedExpression {
32 33
 	}
33 34
 
34 35
 	@Override
35
-	public IPartialExpression compile(ExpressionScope scope) {
36
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
36 37
 		Expression cLeft = left.compile(scope).eval();
37 38
 		TypeMemberGroup members = scope.getTypeMembers(cLeft.type).getOrCreateGroup(this.operator);
38 39
 		ExpressionScope innerScope = scope.withHints(members.predictCallTypes(scope, scope.getResultTypeHints(), 1)[0]);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java View File

@@ -8,8 +8,8 @@ package org.openzen.zenscript.parser.expression;
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15 15
 import org.openzen.zenscript.lexer.ParseException;
@@ -31,9 +31,9 @@ public class ParsedExpressionBracket extends ParsedExpression {
31 31
 	}
32 32
 	
33 33
 	@Override
34
-	public IPartialExpression compile(ExpressionScope scope) {
34
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
35 35
 		if (expressions.size() != 1) {
36
-			return new InvalidExpression(position, CompileExceptionCode.BRACKET_MULTIPLE_EXPRESSIONS, "Bracket expression may have only one expression");
36
+			throw new CompileException(position, CompileExceptionCode.BRACKET_MULTIPLE_EXPRESSIONS, "Bracket expression may have only one expression");
37 37
 		} else {
38 38
 			return expressions.get(0).compile(scope);
39 39
 		}

+ 26
- 30
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java View File

@@ -46,7 +46,7 @@ public class ParsedExpressionCall extends ParsedExpression {
46 46
 	}
47 47
 
48 48
 	@Override
49
-	public IPartialExpression compile(ExpressionScope scope) {
49
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
50 50
 		if (receiver instanceof ParsedExpressionVariable) {
51 51
 			ParsedExpressionVariable variable = (ParsedExpressionVariable) receiver;
52 52
 			for (StoredType hint : scope.hints) {
@@ -64,40 +64,36 @@ public class ParsedExpressionCall extends ParsedExpression {
64 64
 			}
65 65
 		}
66 66
 		
67
-		try {
68
-			if (receiver instanceof ParsedExpressionSuper) {
69
-				// super call (intended as first call in constructor)
70
-				StoredType targetType = scope.getThisType().getSuperType(scope.getTypeRegistry());
71
-				if (targetType == null)
72
-					return new InvalidExpression(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Class has no superclass");
67
+		if (receiver instanceof ParsedExpressionSuper) {
68
+			// super call (intended as first call in constructor)
69
+			StoredType targetType = scope.getThisType().getSuperType(scope.getTypeRegistry());
70
+			if (targetType == null)
71
+				throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Class has no superclass");
73 72
 
74
-				TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
75
-				CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
76
-				FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
77
-				if (!member.isConstructor())
78
-					return new InvalidExpression(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
73
+			TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
74
+			CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
75
+			FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
76
+			if (!member.isConstructor())
77
+				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
79 78
 
80
-				return new ConstructorSuperCallExpression(position, targetType, member, callArguments);
81
-			} else if (receiver instanceof ParsedExpressionThis) {
82
-				// this call (intended as first call in constructor)
83
-				StoredType targetType = scope.getThisType();
79
+			return new ConstructorSuperCallExpression(position, targetType, member, callArguments);
80
+		} else if (receiver instanceof ParsedExpressionThis) {
81
+			// this call (intended as first call in constructor)
82
+			StoredType targetType = scope.getThisType();
84 83
 
85
-				TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
86
-				CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
87
-				FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
88
-				if (!member.isConstructor())
89
-					return new InvalidExpression(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
84
+			TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
85
+			CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
86
+			FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
87
+			if (!member.isConstructor())
88
+				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
90 89
 
91
-				return new ConstructorThisCallExpression(position, scope.getThisType(), member, callArguments);
92
-			}
93
-
94
-			IPartialExpression cReceiver = receiver.compile(scope.withoutHints());
95
-			List<FunctionHeader> headers = cReceiver.getPossibleFunctionHeaders(scope, scope.hints, arguments.arguments.size());
96
-			CallArguments callArguments = arguments.compileCall(position, scope, cReceiver.getGenericCallTypes(), headers);
97
-			return cReceiver.call(position, scope, scope.hints, callArguments);
98
-		} catch (CompileException ex) {
99
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
90
+			return new ConstructorThisCallExpression(position, scope.getThisType(), member, callArguments);
100 91
 		}
92
+
93
+		IPartialExpression cReceiver = receiver.compile(scope.withoutHints());
94
+		List<FunctionHeader> headers = cReceiver.getPossibleFunctionHeaders(scope, scope.hints, arguments.arguments.size());
95
+		CallArguments callArguments = arguments.compileCall(position, scope, cReceiver.getGenericCallTypes(), headers);
96
+		return cReceiver.call(position, scope, scope.hints, callArguments);
101 97
 	}
102 98
 	
103 99
 	@Override

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCast.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11 12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12 13
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -35,7 +36,7 @@ public class ParsedExpressionCast extends ParsedExpression {
35 36
 	}
36 37
 
37 38
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
39
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
39 40
 		StoredType type = this.type.compile(scope);
40 41
 		return value.compile(scope.withHint(type))
41 42
 				.eval()

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java View File

@@ -32,7 +32,7 @@ public class ParsedExpressionCoalesce extends ParsedExpression {
32 32
 	}
33 33
 
34 34
 	@Override
35
-	public IPartialExpression compile(ExpressionScope scope) {
35
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
36 36
 		Expression cLeft = left.compile(scope).eval();
37 37
 		StoredType cLeftType = cLeft.type;
38 38
 		if (!cLeftType.isOptional())

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCompare.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.CompareType;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -34,7 +35,7 @@ public class ParsedExpressionCompare extends ParsedExpression {
34 35
 	}
35 36
 
36 37
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
38
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38 39
 		Expression cLeft = left.compile(scope.withoutHints()).eval();
39 40
 		Expression cRight = right.compile(scope.withHint(cLeft.type)).eval();
40 41
 		return scope.getTypeMembers(cLeft.type).compare(position, scope, type, cLeft, cRight);

+ 4
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionConditional.java View File

@@ -7,10 +7,10 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zencode.shared.CompileExceptionCode;
11 12
 import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
14 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
@@ -35,7 +35,7 @@ public class ParsedExpressionConditional extends ParsedExpression {
35 35
 	}
36 36
 
37 37
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
38
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
39 39
 		Expression cIfThen = ifThen.compile(scope).eval();
40 40
 		Expression cIfElse = ifElse.compile(scope).eval();
41 41
 		
@@ -45,7 +45,7 @@ public class ParsedExpressionConditional extends ParsedExpression {
45 45
 		for (StoredType hint : scope.hints) {
46 46
 			if (thenMembers.canCastImplicit(hint) && elseMembers.canCastImplicit(hint)) {
47 47
 				if (resultType != null)
48
-					return new InvalidExpression(position, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Not sure which type to use");
48
+					throw new CompileException(position, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Not sure which type to use");
49 49
 				
50 50
 				resultType = hint;
51 51
 			}
@@ -55,7 +55,7 @@ public class ParsedExpressionConditional extends ParsedExpression {
55 55
 			resultType = thenMembers.union(cIfElse.type);
56 56
 		
57 57
 		if (resultType == null)
58
-			return new InvalidExpression(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + cIfThen.type + " and " + cIfElse.type);
58
+			throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + cIfThen.type + " and " + cIfElse.type);
59 59
 		
60 60
 		cIfThen = cIfThen.castImplicit(position, scope, resultType);
61 61
 		cIfElse = cIfElse.castImplicit(position, scope, resultType);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFloat.java View File

@@ -48,7 +48,7 @@ public class ParsedExpressionFloat extends ParsedExpression {
48 48
 	}
49 49
 
50 50
 	@Override
51
-	public IPartialExpression compile(ExpressionScope scope) {
51
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
52 52
 		if (scope.hints.isEmpty())
53 53
 			return new ConstantDoubleExpression(position, value);
54 54
 		
@@ -87,9 +87,9 @@ public class ParsedExpressionFloat extends ParsedExpression {
87 87
 				types.append(scope.hints.get(i).toString());
88 88
 			}
89 89
 
90
-			return new InvalidExpression(position, CompileExceptionCode.INVALID_CAST, "Cannot cast a floating-point value to any of these types: " + types);
90
+			throw new CompileException(position, CompileExceptionCode.INVALID_CAST, "Cannot cast a floating-point value to any of these types: " + types);
91 91
 		} else {
92
-			return new InvalidExpression(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
92
+			throw new CompileException(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
93 93
 		}
94 94
 	}
95 95
 

+ 10
- 6
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.Map;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.GenericMapper;
@@ -25,7 +26,8 @@ import org.openzen.zenscript.codemodel.scope.StatementScope;
25 26
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26 27
 import org.openzen.zenscript.codemodel.type.StoredType;
27 28
 import org.openzen.zenscript.codemodel.type.TypeID;
28
-import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
29
+import org.openzen.zenscript.codemodel.type.storage.SharedStorageTag;
30
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
29 31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
30 32
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
31 33
 
@@ -45,9 +47,10 @@ public class ParsedExpressionFunction extends ParsedExpression {
45 47
 	}
46 48
 
47 49
 	@Override
48
-	public IPartialExpression compile(ExpressionScope scope) {
50
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
49 51
 		FunctionHeader definedHeader = header.compile(scope);
50 52
 		FunctionHeader header = definedHeader;
53
+		StorageTag storage = SharedStorageTag.INSTANCE;
51 54
 		for (StoredType hint : scope.hints) {
52 55
 			if (hint.getNormalized().type instanceof FunctionTypeID) {
53 56
 				FunctionTypeID functionHint = (FunctionTypeID) hint.getNormalized().type;
@@ -56,6 +59,7 @@ public class ParsedExpressionFunction extends ParsedExpression {
56 59
 						return new InvalidExpression(position, hint, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Ambiguity trying to resolve function types, can't decide for the type");
57 60
 					
58 61
 					header = functionHint.header.forLambda(definedHeader);
62
+					storage = hint.storage;
59 63
 				}
60 64
 			}
61 65
 		}
@@ -70,22 +74,22 @@ public class ParsedExpressionFunction extends ParsedExpression {
70 74
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
71 75
 		Statement statements = body.compile(innerScope, header);
72 76
 		
73
-		if (header.getReturnType().isBasic(BasicTypeID.UNDETERMINED)) {
77
+		if (header.getReturnType().isBasic(BasicTypeID.UNDETERMINED))
74 78
 			header.setReturnType(statements.getReturnType());
75
-		}
79
+		
76 80
 		if (!scope.genericInferenceMap.isEmpty()) {
77 81
 			// perform type parameter inference
78 82
 			StoredType returnType = statements.getReturnType();
79 83
 			Map<TypeParameter, TypeID> inferredTypes = returnType.type.inferTypeParameters(scope.getMemberCache(), genericHeader.getReturnType().type);
80 84
 			if (inferredTypes == null)
81
-				return new InvalidExpression(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
85
+				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
82 86
 			
83 87
 			scope.genericInferenceMap.putAll(inferredTypes);
84 88
 		}
85 89
 		
86 90
 		StoredType functionType = scope.getTypeRegistry()
87 91
 				.getFunction(genericHeader.withGenericArguments(scope.getTypeRegistry(), new GenericMapper(scope.getTypeRegistry(), scope.genericInferenceMap)))
88
-				.stored(UniqueStorageTag.INSTANCE);
92
+				.stored(storage);
89 93
 		return new FunctionExpression(position, functionType, closure, header, statements);
90 94
 	}
91 95
 	

+ 10
- 9
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12 13
 import org.openzen.zenscript.codemodel.OperatorType;
13 14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
@@ -36,7 +37,7 @@ public class ParsedExpressionIndex extends ParsedExpression {
36 37
 	}
37 38
 
38 39
 	@Override
39
-	public IPartialExpression compile(ExpressionScope scope) {
40
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
40 41
 		return new PartialIndexedExpression(scope);
41 42
 	}
42 43
 
@@ -49,13 +50,13 @@ public class ParsedExpressionIndex extends ParsedExpression {
49 50
 		private final ExpressionScope scope;
50 51
 		private final Expression target;
51 52
 		
52
-		private PartialIndexedExpression(ExpressionScope scope) {
53
+		private PartialIndexedExpression(ExpressionScope scope) throws CompileException {
53 54
 			this.scope = scope;
54 55
 			target = value.compile(scope.withoutHints()).eval();
55 56
 		}
56 57
 		
57 58
 		@Override
58
-		public Expression eval() {
59
+		public Expression eval() throws CompileException {
59 60
 			TypeMemberGroup members = scope.getTypeMembers(target.type).getOrCreateGroup(OperatorType.INDEXGET);
60 61
 			List<StoredType>[] predictedTypes = members.predictCallTypes(scope, scope.hints, indexes.size());
61 62
 			Expression[] arguments = new Expression[indexes.size()];
@@ -66,27 +67,27 @@ public class ParsedExpressionIndex extends ParsedExpression {
66 67
 		}
67 68
 
68 69
 		@Override
69
-		public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) {
70
+		public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
70 71
 			return eval().predictCallTypes(scope, hints, arguments);
71 72
 		}
72 73
 		
73 74
 		@Override
74
-		public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) {
75
+		public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
75 76
 			return eval().getPossibleFunctionHeaders(scope, hints, arguments);
76 77
 		}
77 78
 
78 79
 		@Override
79
-		public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
80
+		public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
80 81
 			return eval().getMember(position, scope, hints, name);
81 82
 		}
82 83
 
83 84
 		@Override
84
-		public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
85
+		public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
85 86
 			return eval().call(position, scope, hints, arguments);
86 87
 		}
87 88
 		
88 89
 		@Override
89
-		public Expression assign(CodePosition position, TypeScope scope, Expression value) {
90
+		public Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
90 91
 			TypeMemberGroup members = scope.getTypeMembers(target.type).getOrCreateGroup(OperatorType.INDEXSET);
91 92
 			List<StoredType>[] predictedTypes = members.predictCallTypes(scope, this.scope.hints, indexes.size() + 1);
92 93
 			
@@ -105,7 +106,7 @@ public class ParsedExpressionIndex extends ParsedExpression {
105 106
 			return predictedTypes[indexes.size()];
106 107
 		}
107 108
 		
108
-		private Expression getLength(CodePosition position) {
109
+		private Expression getLength(CodePosition position) throws CompileException {
109 110
 			return target.getMember(position, scope, scope.hints, new GenericName("length")).eval();
110 111
 		}
111 112
 

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java View File

@@ -110,7 +110,7 @@ public class ParsedExpressionInt extends ParsedExpression {
110 110
 	}
111 111
 	
112 112
 	@Override
113
-	public Expression compile(ExpressionScope scope) {
113
+	public Expression compile(ExpressionScope scope) throws CompileException {
114 114
 		if (suffix.equals("L") || suffix.equals("l"))
115 115
 			return new ConstantLongExpression(position, value);
116 116
 		if (suffix.equals("UL") || suffix.equals("ul"))
@@ -182,7 +182,7 @@ public class ParsedExpressionInt extends ParsedExpression {
182 182
 			else
183 183
 				return new ConstantLongExpression(position, value);
184 184
 		} else {
185
-			return new InvalidExpression(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
185
+			throw new CompileException(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
186 186
 		}
187 187
 	}
188 188
 	

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIs.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zenscript.codemodel.expression.Expression;
10 11
 import org.openzen.zenscript.codemodel.expression.IsExpression;
11 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -30,7 +31,7 @@ public class ParsedExpressionIs extends ParsedExpression {
30 31
 	}
31 32
 
32 33
 	@Override
33
-	public IPartialExpression compile(ExpressionScope scope) {
34
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
34 35
 		TypeID isType = type.compileUnstored(scope);
35 36
 		Expression expression = this.expression.compile(scope.withHint(isType.stored(BorrowStorageTag.INVOCATION))).eval();
36 37
 		return new IsExpression(position, expression, isType);

+ 10
- 14
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java View File

@@ -44,7 +44,7 @@ public class ParsedExpressionMap extends ParsedExpression {
44 44
 	}
45 45
 
46 46
 	@Override
47
-	public IPartialExpression compile(ExpressionScope scope) {
47
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
48 48
 		StoredType usedHint = null;
49 49
 		List<StoredType> keyHints = new ArrayList<>();
50 50
 		List<StoredType> valueHints = new ArrayList<>();
@@ -74,15 +74,11 @@ public class ParsedExpressionMap extends ParsedExpression {
74 74
 		}
75 75
 		
76 76
 		if (keys.isEmpty() && keyHints.size() == 1) {
77
-			try {
78
-				FunctionalMemberRef constructor = scope
79
-							.getTypeMembers(usedHint)
80
-							.getOrCreateGroup(OperatorType.CONSTRUCTOR)
81
-							.selectMethod(position, scope, CallArguments.EMPTY, true, true);
82
-					return new NewExpression(position, usedHint, constructor, CallArguments.EMPTY);
83
-			} catch (CompileException ex) {
84
-				return new InvalidExpression(ex.position, ex.code, ex.getMessage());
85
-			}
77
+			FunctionalMemberRef constructor = scope
78
+					.getTypeMembers(usedHint)
79
+					.getOrCreateGroup(OperatorType.CONSTRUCTOR)
80
+					.selectMethod(position, scope, CallArguments.EMPTY, true, true);
81
+			return new NewExpression(position, usedHint, constructor, CallArguments.EMPTY);
86 82
 		}
87 83
 		
88 84
 		if (!hasAssocHint && scope.hints.size() == 1) {
@@ -90,7 +86,7 @@ public class ParsedExpressionMap extends ParsedExpression {
90 86
 			StoredType hint = scope.hints.get(0);
91 87
 			for (int i = 0; i < keys.size(); i++) {
92 88
 				if (keys.get(i) != null)
93
-					return new InvalidExpression(position, CompileExceptionCode.UNSUPPORTED_NAMED_ARGUMENTS, "Named constructor arguments not yet supported");
89
+					throw new CompileException(position, CompileExceptionCode.UNSUPPORTED_NAMED_ARGUMENTS, "Named constructor arguments not yet supported");
94 90
 			}
95 91
 			ParsedCallArguments arguments = new ParsedCallArguments(null, values);
96 92
 			return ParsedNewExpression.compile(position, hint, arguments, scope);
@@ -101,7 +97,7 @@ public class ParsedExpressionMap extends ParsedExpression {
101 97
 
102 98
 		for (int i = 0; i < keys.size(); i++) {
103 99
 			if (keys.get(i) == null)
104
-				return new InvalidExpression(position, CompileExceptionCode.MISSING_MAP_KEY, "Missing key");
100
+				throw new CompileException(position, CompileExceptionCode.MISSING_MAP_KEY, "Missing key");
105 101
 			
106 102
 			cKeys[i] = keys.get(i).compileKey(scope.withHints(keyHints));
107 103
 			cValues[i] = values.get(i).compile(scope.withHints(valueHints)).eval();
@@ -119,7 +115,7 @@ public class ParsedExpressionMap extends ParsedExpression {
119 115
 			}
120 116
 		}
121 117
 		if (keyType == null)
122
-			return new InvalidExpression(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
118
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
123 119
 		
124 120
 		for (int i = 0; i < cKeys.length; i++)
125 121
 			cKeys[i] = cKeys[i].castImplicit(position, scope, keyType);
@@ -136,7 +132,7 @@ public class ParsedExpressionMap extends ParsedExpression {
136 132
 			}
137 133
 		}
138 134
 		if (valueType == null)
139
-			return new InvalidExpression(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
135
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
140 136
 		
141 137
 		for (int i = 0; i < cValues.length; i++)
142 138
 			cValues[i] = cValues[i].castImplicit(position, scope, valueType);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java View File

@@ -8,8 +8,8 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
@@ -34,7 +34,7 @@ public class ParsedExpressionMember extends ParsedExpression {
34 34
 	}
35 35
 
36 36
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
37
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38 38
 		IPartialExpression cValue = value.compile(scope.withoutHints());
39 39
 		TypeID[] typeParameters = IParsedType.compileList(genericParameters, scope);
40 40
 		IPartialExpression member = cValue.getMember(
@@ -43,7 +43,7 @@ public class ParsedExpressionMember extends ParsedExpression {
43 43
 				scope.hints,
44 44
 				new GenericName(this.member, typeParameters));
45 45
 		if (member == null)
46
-			return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
46
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
47 47
 		
48 48
 		return member;
49 49
 	}

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOpAssign.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.OperatorType;
11 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -14,7 +15,6 @@ import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberGroup;
15 16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16 17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
-import org.openzen.zenscript.parser.PrecompilationState;
18 18
 
19 19
 /**
20 20
  *
@@ -34,7 +34,7 @@ public class ParsedExpressionOpAssign extends ParsedExpression {
34 34
 	}
35 35
 
36 36
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
37
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38 38
 		Expression cLeft = left.compile(scope).eval();
39 39
 		TypeMembers typeMembers = scope.getTypeMembers(cLeft.type);
40 40
 		TypeMemberGroup members = typeMembers.getOrCreateGroup(operator);

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOrOr.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.expression.Expression;
11 12
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -29,7 +30,7 @@ public class ParsedExpressionOrOr extends ParsedExpression {
29 30
 	}
30 31
 
31 32
 	@Override
32
-	public IPartialExpression compile(ExpressionScope scope) {
33
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
33 34
 		Expression cLeft = left.compile(scope.withHints(BasicTypeID.HINT_BOOL)).eval().castImplicit(position, scope, BasicTypeID.BOOL.stored);
34 35
 		Expression cRight = right.compile(scope.withHints(BasicTypeID.HINT_BOOL)).eval().castImplicit(position, scope, BasicTypeID.BOOL.stored);
35 36
 		return new OrOrExpression(position, cLeft, cRight);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOuter.java View File

@@ -6,8 +6,8 @@
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
11 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12 12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
@@ -27,10 +27,10 @@ public class ParsedExpressionOuter extends ParsedExpression {
27 27
 	}
28 28
 
29 29
 	@Override
30
-	public IPartialExpression compile(ExpressionScope scope) {
30
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
31 31
 		StoredType thisType = scope.getThisType();
32 32
 		if (thisType == null || !(thisType.type instanceof DefinitionTypeID))
33
-			return new InvalidExpression(position, CompileExceptionCode.USING_THIS_OUTSIDE_TYPE, "Not in a type");
33
+			throw new CompileException(position, CompileExceptionCode.USING_THIS_OUTSIDE_TYPE, "Not in a type");
34 34
 		
35 35
 		return scope.getOuterInstance(position);
36 36
 	}

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.OperatorType;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -28,7 +29,7 @@ public class ParsedExpressionPostCall extends ParsedExpression {
28 29
 	}
29 30
 
30 31
 	@Override
31
-	public IPartialExpression compile(ExpressionScope scope) {
32
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
32 33
 		Expression cValue = value.compile(scope).eval();
33 34
 		return scope.getTypeMembers(cValue.type).getOrCreateGroup(operator).callPostfix(position, scope, cValue);
34 35
 	}

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.parser.expression;
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
13 14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -31,7 +32,7 @@ public class ParsedExpressionRange extends ParsedExpression {
31 32
 	}
32 33
 
33 34
 	@Override
34
-	public IPartialExpression compile(ExpressionScope scope) {
35
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
35 36
 		List<StoredType> fromHints = new ArrayList<>();
36 37
 		List<StoredType> toHints = new ArrayList<>();
37 38
 		

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSame.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.OperatorType;
11 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -35,7 +36,7 @@ public class ParsedExpressionSame extends ParsedExpression {
35 36
 	}
36 37
 
37 38
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
39
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
39 40
 		Expression cLeft = left.compile(scope.withoutHints()).eval();
40 41
 		Expression cRight = right.compile(scope.withHint(cLeft.type)).eval();
41 42
 		return scope.getTypeMembers(cLeft.type)

+ 2
- 11
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java View File

@@ -34,17 +34,8 @@ public class ParsedExpressionString extends ParsedExpression {
34 34
 
35 35
 	@Override
36 36
 	public IPartialExpression compile(ExpressionScope scope) {
37
-		if (value.length() == 1) {
38
-			if (scope.hints.contains(BasicTypeID.CHAR)) {
39
-				return new ConstantCharExpression(position, value.charAt(0));
40
-			} else {
41
-				for (StoredType type : scope.hints)
42
-					if (type.type instanceof StringTypeID)
43
-						return new ConstantStringExpression(position, value);
44
-				
45
-				return new ConstantCharExpression(position, value.charAt(0));
46
-			}
47
-		}
37
+		if (value.length() == 1 && scope.hints.contains(BasicTypeID.CHAR.stored))
38
+			return new ConstantCharExpression(position, value.charAt(0));
48 39
 		
49 40
 		return new ConstantStringExpression(position, value);
50 41
 	}

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSuper.java View File

@@ -24,11 +24,11 @@ public class ParsedExpressionSuper extends ParsedExpression {
24 24
 	}
25 25
 	
26 26
 	@Override
27
-	public IPartialExpression compile(ExpressionScope scope) {
27
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
28 28
 		StoredType type = scope.getThisType();
29 29
 		StoredType targetType = type.getSuperType(scope.getTypeRegistry());
30 30
 		if (targetType == null)
31
-			return new InvalidExpression(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Type has no superclass");
31
+			throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Type has no superclass");
32 32
 		
33 33
 		return new PartialTypeExpression(position, targetType.type, null);
34 34
 	}

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionUnary.java View File

@@ -7,6 +7,7 @@
7 7
 package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10 11
 import org.openzen.zenscript.codemodel.OperatorType;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -28,7 +29,7 @@ public class ParsedExpressionUnary extends ParsedExpression {
28 29
 	}
29 30
 
30 31
 	@Override
31
-	public IPartialExpression compile(ExpressionScope scope) {
32
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
32 33
 		Expression cValue = value.compile(scope).eval();
33 34
 		return scope.getTypeMembers(cValue.type)
34 35
 				.unary(position, scope, operator, cValue);

+ 2
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java View File

@@ -14,7 +14,6 @@ import org.openzen.zencode.shared.CompileExceptionCode;
14 14
 import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
15 15
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
16 16
 import org.openzen.zenscript.codemodel.expression.Expression;
17
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
18 17
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
19 18
 import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
20 19
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
@@ -49,7 +48,7 @@ public class ParsedExpressionVariable extends ParsedExpression {
49 48
 	}
50 49
 
51 50
 	@Override
52
-	public IPartialExpression compile(ExpressionScope scope) {
51
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
53 52
 		TypeID[] genericArguments = TypeID.NONE;
54 53
 		if (genericParameters != null) {
55 54
 			genericArguments = new TypeID[genericParameters.size()];
@@ -71,7 +70,7 @@ public class ParsedExpressionVariable extends ParsedExpression {
71 70
 					return new VariantValueExpression(position, hint, option);
72 71
 			}
73 72
 			
74
-			return new InvalidExpression(position, CompileExceptionCode.UNDEFINED_VARIABLE, "No such symbol: " + name);
73
+			throw new CompileException(position, CompileExceptionCode.UNDEFINED_VARIABLE, "No such symbol: " + name);
75 74
 		} else {
76 75
 			return result;
77 76
 		}

+ 15
- 21
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java View File

@@ -10,13 +10,11 @@ import org.openzen.zencode.shared.CodePosition;
10 10
 import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zencode.shared.CompileExceptionCode;
12 12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
14 13
 import org.openzen.zenscript.codemodel.expression.MatchExpression;
15 14
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
16 15
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
17 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
18 17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
20 18
 import org.openzen.zenscript.codemodel.type.StoredType;
21 19
 
22 20
 /**
@@ -35,27 +33,23 @@ public class ParsedMatchExpression extends ParsedExpression {
35 33
 	}
36 34
 
37 35
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
39
-		try {
40
-			Expression cValue = value.compile(scope).eval();
41
-			MatchExpression.Case[] cCases = new MatchExpression.Case[cases.size()];
42
-			for (int i = 0; i < cases.size(); i++) {
43
-				Case matchCase = cases.get(i);
44
-				cCases[i] = matchCase.compile(cValue.type, scope);
45
-			}
46
-
47
-			StoredType result = cCases[0].value.type;
48
-			for (int i = 1; i < cCases.length; i++) {
49
-				StoredType oldResult = result;
50
-				result = scope.getTypeMembers(result).union(cCases[i].value.type);
51
-				if (result == null)
52
-					return new InvalidExpression(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "Matches have different types: " + oldResult + " and " + cCases[i].value.type);
53
-			}
36
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
37
+		Expression cValue = value.compile(scope).eval();
38
+		MatchExpression.Case[] cCases = new MatchExpression.Case[cases.size()];
39
+		for (int i = 0; i < cases.size(); i++) {
40
+			Case matchCase = cases.get(i);
41
+			cCases[i] = matchCase.compile(cValue.type, scope);
42
+		}
54 43
 
55
-			return new MatchExpression(position, cValue, result, cCases);
56
-		} catch (CompileException ex) {
57
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
44
+		StoredType result = cCases[0].value.type;
45
+		for (int i = 1; i < cCases.length; i++) {
46
+			StoredType oldResult = result;
47
+			result = scope.getTypeMembers(result).union(cCases[i].value.type);
48
+			if (result == null)
49
+				throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "Matches have different types: " + oldResult + " and " + cCases[i].value.type);
58 50
 		}
51
+
52
+		return new MatchExpression(position, cValue, result, cCases);
59 53
 	}
60 54
 
61 55
 	@Override

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedPanicExpression.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zenscript.codemodel.expression.PanicExpression;
10 11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11 12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
@@ -25,7 +26,7 @@ public class ParsedPanicExpression extends ParsedExpression {
25 26
 	}
26 27
 	
27 28
 	@Override
28
-	public IPartialExpression compile(ExpressionScope scope) {
29
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
29 30
 		return new PanicExpression(position, scope.getResultTypeHints().isEmpty() ? BasicTypeID.VOID.stored : scope.getResultTypeHints().get(0), value.compile(scope).eval());
30 31
 	}
31 32
 

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedThrowExpression.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zenscript.codemodel.expression.Expression;
10 11
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
11 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -27,7 +28,7 @@ public class ParsedThrowExpression extends ParsedExpression {
27 28
 	}
28 29
 
29 30
 	@Override
30
-	public IPartialExpression compile(ExpressionScope scope) {
31
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
31 32
 		Expression cValue = value.compile(scope).eval();
32 33
 		StoredType resultType = BasicTypeID.VOID.stored;
33 34
 		if (scope.getResultTypeHints().size() == 1)

+ 4
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryConvertExpression.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zencode.shared.CompileExceptionCode;
10 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -29,10 +30,10 @@ public class ParsedTryConvertExpression extends ParsedExpression {
29 30
 	}
30 31
 
31 32
 	@Override
32
-	public IPartialExpression compile(ExpressionScope scope) {
33
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
33 34
 		Expression cValue = value.compile(scope).eval();
34 35
 		if (scope.getFunctionHeader() == null)
35
-			return new InvalidExpression(position, CompileExceptionCode.TRY_CONVERT_OUTSIDE_FUNCTION, "try? can only be used inside functions");
36
+			throw new CompileException(position, CompileExceptionCode.TRY_CONVERT_OUTSIDE_FUNCTION, "try? can only be used inside functions");
36 37
 		
37 38
 		HighLevelDefinition result = scope.getTypeRegistry().stdlib.getDefinition("Result");
38 39
 		if (cValue.thrownType != null) {
@@ -40,7 +41,7 @@ public class ParsedTryConvertExpression extends ParsedExpression {
40 41
 			DefinitionTypeID resultType = scope.getTypeRegistry().getForDefinition(result, cValue.type.type, cValue.thrownType.type);
41 42
 			return new TryConvertExpression(position, resultType.stored(cValue.type.storage), cValue);
42 43
 		} else {
43
-			return new InvalidExpression(position, CompileExceptionCode.TRY_CONVERT_ILLEGAL_TARGET, "try? can only be used on expressions that throw");
44
+			throw new CompileException(position, CompileExceptionCode.TRY_CONVERT_ILLEGAL_TARGET, "try? can only be used on expressions that throw");
44 45
 		}
45 46
 	}
46 47
 

+ 4
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryRethrowExpression.java View File

@@ -6,10 +6,10 @@
6 6
 package org.openzen.zenscript.parser.expression;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zencode.shared.CompileExceptionCode;
10 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13 13
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
15 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -31,7 +31,7 @@ public class ParsedTryRethrowExpression extends ParsedExpression {
31 31
 	}
32 32
 
33 33
 	@Override
34
-	public IPartialExpression compile(ExpressionScope scope) {
34
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
35 35
 		HighLevelDefinition result = scope.getTypeRegistry().stdlib.getDefinition("Result");
36 36
 		
37 37
 		Expression cSource = source.compile(scope).eval();
@@ -55,9 +55,9 @@ public class ParsedTryRethrowExpression extends ParsedExpression {
55 55
 			}
56 56
 			
57 57
 			if (scope.getFunctionHeader() == null)
58
-				return new InvalidExpression(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "type is not a Result type, cannot convert");
58
+				throw new CompileException(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "type is not a Result type, cannot convert");
59 59
 			
60
-			return new InvalidExpression(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "this expression doesn't throw an exception nor returns a result");
60
+			throw new CompileException(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "this expression doesn't throw an exception nor returns a result");
61 61
 		}
62 62
 	}
63 63
 

+ 6
- 6
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java View File

@@ -6,12 +6,11 @@
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8 8
 import java.util.List;
9
-import java.util.function.Function;
10 9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15 14
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
16 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17 16
 import org.openzen.zenscript.codemodel.statement.CatchClause;
@@ -20,6 +19,7 @@ import org.openzen.zenscript.codemodel.statement.VarStatement;
20 19
 import org.openzen.zenscript.codemodel.type.GenericName;
21 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
22 21
 import org.openzen.zenscript.codemodel.scope.StatementScope;
22
+import org.openzen.zenscript.codemodel.statement.VariableID;
23 23
 import org.openzen.zenscript.codemodel.type.StoredType;
24 24
 import org.openzen.zenscript.codemodel.type.TypeID;
25 25
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
@@ -44,7 +44,7 @@ public class ParsedCatchClause {
44 44
 	}
45 45
 	
46 46
 	public CatchClause compile(StatementScope scope) {
47
-		VarStatement exceptionVariable = new VarStatement(position, exceptionName, exceptionType.compile(scope), null, true);
47
+		VarStatement exceptionVariable = new VarStatement(position, new VariableID(), exceptionName, exceptionType.compile(scope), null, true);
48 48
 		CatchScope localScope = new CatchScope(scope, exceptionVariable);
49 49
 		return new CatchClause(position, exceptionVariable, content.compile(localScope));
50 50
 	}
@@ -59,7 +59,7 @@ public class ParsedCatchClause {
59 59
 		}
60 60
 	
61 61
 		@Override
62
-		public IPartialExpression get(CodePosition position, GenericName name) {
62
+		public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
63 63
 			if (name.hasNoArguments() && exceptionVariable.name.equals(name.name))
64 64
 				return new GetLocalVariableExpression(position, exceptionVariable);
65 65
 
@@ -97,12 +97,12 @@ public class ParsedCatchClause {
97 97
 		}
98 98
 
99 99
 		@Override
100
-		public Function<CodePosition, Expression> getDollar() {
100
+		public DollarEvaluator getDollar() {
101 101
 			return outer.getDollar();
102 102
 		}
103 103
 
104 104
 		@Override
105
-		public IPartialExpression getOuterInstance(CodePosition position) {
105
+		public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
106 106
 			return outer.getOuterInstance(position);
107 107
 		}
108 108
 

+ 15
- 9
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8
+import org.openzen.zencode.shared.CompileException;
8 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9 10
 import org.openzen.zenscript.codemodel.expression.Expression;
10 11
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
@@ -13,6 +14,7 @@ import org.openzen.zenscript.codemodel.statement.Statement;
13 14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14 15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15 16
 import org.openzen.zenscript.codemodel.scope.StatementScope;
17
+import org.openzen.zenscript.codemodel.statement.InvalidStatement;
16 18
 import org.openzen.zenscript.parser.expression.ParsedExpression;
17 19
 
18 20
 /**
@@ -28,15 +30,19 @@ public class ParsedLambdaFunctionBody implements ParsedFunctionBody {
28 30
 	
29 31
 	@Override
30 32
 	public Statement compile(StatementScope scope, FunctionHeader header) {
31
-		if (header.getReturnType().isBasic(BasicTypeID.VOID)) {
32
-			Expression value = this.value.compile(new ExpressionScope(scope)).eval();
33
-			return new ExpressionStatement(value.position, value);
34
-		} else {
35
-			Expression returnValue = value
36
-					.compile(new ExpressionScope(scope, header.getReturnType()))
37
-					.eval()
38
-					.castImplicit(value.position, scope, header.getReturnType());
39
-			return new ReturnStatement(value.position, returnValue);
33
+		try {
34
+			if (header.getReturnType().isBasic(BasicTypeID.VOID)) {
35
+				Expression value = this.value.compile(new ExpressionScope(scope)).eval();
36
+				return new ExpressionStatement(value.position, value);
37
+			} else {
38
+				Expression returnValue = value
39
+						.compile(new ExpressionScope(scope, header.getReturnType()))
40
+						.eval()
41
+						.castImplicit(value.position, scope, header.getReturnType());
42
+				return new ReturnStatement(value.position, returnValue);
43
+			}
44
+		} catch (CompileException ex) {
45
+			return new InvalidStatement(ex);
40 46
 		}
41 47
 	}
42 48
 }

+ 8
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementDoWhile.java View File

@@ -6,8 +6,10 @@
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
11 13
 import org.openzen.zenscript.codemodel.statement.DoWhileStatement;
12 14
 import org.openzen.zenscript.codemodel.statement.Statement;
13 15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -36,10 +38,15 @@ public class ParsedStatementDoWhile extends ParsedStatement {
36 38
 
37 39
 	@Override
38 40
 	public Statement compile(StatementScope scope) {
39
-		Expression condition = this.condition
41
+		Expression condition;
42
+		try {
43
+			condition = this.condition
40 44
 				.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL))
41 45
 				.eval()
42 46
 				.castImplicit(position, scope, BasicTypeID.BOOL.stored);
47
+		} catch (CompileException ex) {
48
+			condition = new InvalidExpression(BasicTypeID.BOOL.stored, ex);
49
+		}
43 50
 		
44 51
 		DoWhileStatement result = new DoWhileStatement(position, label, condition);
45 52
 		LoopScope innerScope = new LoopScope(result, scope);

+ 7
- 2
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementExpression.java View File

@@ -1,13 +1,14 @@
1 1
 package org.openzen.zenscript.parser.statements;
2 2
 
3 3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.CompileException;
4 5
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
5 6
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
6 7
 import org.openzen.zenscript.codemodel.statement.Statement;
7 8
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
8 9
 import org.openzen.zenscript.codemodel.scope.StatementScope;
10
+import org.openzen.zenscript.codemodel.statement.InvalidStatement;
9 11
 import org.openzen.zenscript.parser.ParsedAnnotation;
10
-import org.openzen.zenscript.parser.PrecompilationState;
11 12
 import org.openzen.zenscript.parser.expression.ParsedExpression;
12 13
 
13 14
 public class ParsedStatementExpression extends ParsedStatement {
@@ -21,6 +22,10 @@ public class ParsedStatementExpression extends ParsedStatement {
21 22
 
22 23
 	@Override
23 24
 	public Statement compile(StatementScope scope) {
24
-		return result(new ExpressionStatement(position, this.expression.compile(new ExpressionScope(scope)).eval()), scope);
25
+		try {
26
+			return result(new ExpressionStatement(position, this.expression.compile(new ExpressionScope(scope)).eval()), scope);
27
+		} catch (CompileException ex) {
28
+			return result(new InvalidStatement(ex), scope);
29
+		}
25 30
 	}
26 31
 }

+ 22
- 16
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementForeach.java View File

@@ -1,6 +1,7 @@
1 1
 package org.openzen.zenscript.parser.statements;
2 2
 
3 3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.CompileException;
4 5
 import org.openzen.zencode.shared.CompileExceptionCode;
5 6
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
6 7
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -13,6 +14,7 @@ import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13 14
 import org.openzen.zenscript.codemodel.scope.ForeachScope;
14 15
 import org.openzen.zenscript.codemodel.scope.StatementScope;
15 16
 import org.openzen.zenscript.codemodel.statement.InvalidStatement;
17
+import org.openzen.zenscript.codemodel.statement.VariableID;
16 18
 import org.openzen.zenscript.codemodel.type.StoredType;
17 19
 import org.openzen.zenscript.parser.ParsedAnnotation;
18 20
 import org.openzen.zenscript.parser.expression.ParsedExpression;
@@ -32,21 +34,25 @@ public class ParsedStatementForeach extends ParsedStatement {
32 34
 
33 35
 	@Override
34 36
 	public Statement compile(StatementScope scope) {
35
-		Expression list = this.list.compile(new ExpressionScope(scope)).eval();
36
-		
37
-		TypeMembers members = scope.getTypeMembers(list.type);
38
-		IteratorMemberRef iterator = members.getIterator(varnames.length);
39
-		if (iterator == null)
40
-			return new InvalidStatement(position, CompileExceptionCode.NO_SUCH_ITERATOR, list.type + " doesn't have an iterator with " + varnames.length + " variables");
41
-		
42
-		StoredType[] loopTypes = iterator.types;
43
-		VarStatement[] variables = new VarStatement[varnames.length];
44
-		for (int i = 0; i < variables.length; i++)
45
-			variables[i] = new VarStatement(position, varnames[i], loopTypes[i], null, true);
46
-		
47
-		ForeachStatement statement = new ForeachStatement(position, variables, iterator, list);
48
-		ForeachScope innerScope = new ForeachScope(statement, scope);
49
-		statement.content = this.body.compile(innerScope);
50
-		return result(statement, scope);
37
+		try {
38
+			Expression list = this.list.compile(new ExpressionScope(scope)).eval();
39
+
40
+			TypeMembers members = scope.getTypeMembers(list.type);
41
+			IteratorMemberRef iterator = members.getIterator(varnames.length);
42
+			if (iterator == null)
43
+				return new InvalidStatement(position, CompileExceptionCode.NO_SUCH_ITERATOR, list.type + " doesn't have an iterator with " + varnames.length + " variables");
44
+
45
+			StoredType[] loopTypes = iterator.types;
46
+			VarStatement[] variables = new VarStatement[varnames.length];
47
+			for (int i = 0; i < variables.length; i++)
48
+				variables[i] = new VarStatement(position, new VariableID(), varnames[i], loopTypes[i], null, true);
49
+
50
+			ForeachStatement statement = new ForeachStatement(position, variables, iterator, list);
51
+			ForeachScope innerScope = new ForeachScope(statement, scope);
52
+			statement.content = this.body.compile(innerScope);
53
+			return result(statement, scope);
54
+		} catch (CompileException ex) {
55
+			return result(new InvalidStatement(ex), scope);
56
+		}
51 57
 	}
52 58
 }

+ 9
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementIf.java View File

@@ -1,8 +1,10 @@
1 1
 package org.openzen.zenscript.parser.statements;
2 2
 
3 3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.CompileException;
4 5
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
5 6
 import org.openzen.zenscript.codemodel.expression.Expression;
7
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
6 8
 import org.openzen.zenscript.codemodel.statement.IfStatement;
7 9
 import org.openzen.zenscript.codemodel.statement.Statement;
8 10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -26,7 +28,13 @@ public class ParsedStatementIf extends ParsedStatement {
26 28
 
27 29
 	@Override
28 30
 	public Statement compile(StatementScope scope) {
29
-		Expression condition = this.condition.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL)).eval();
31
+		Expression condition;
32
+		try {
33
+			condition = this.condition.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL)).eval();
34
+		} catch (CompileException ex) {
35
+			condition = new InvalidExpression(BasicTypeID.BOOL.stored, ex);
36
+		}
37
+		
30 38
 		Statement onThen = this.onThen.compile(scope);
31 39
 		Statement onElse = this.onElse == null ? null : this.onElse.compile(scope);
32 40
  		return result(new IfStatement(position, condition, onThen, onElse), scope);

+ 9
- 3
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementLock.java View File

@@ -6,12 +6,14 @@
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9 10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10 11
 import org.openzen.zenscript.codemodel.expression.Expression;
11 12
 import org.openzen.zenscript.codemodel.statement.LockStatement;
12 13
 import org.openzen.zenscript.codemodel.statement.Statement;
13 14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14 15
 import org.openzen.zenscript.codemodel.scope.StatementScope;
16
+import org.openzen.zenscript.codemodel.statement.InvalidStatement;
15 17
 import org.openzen.zenscript.parser.ParsedAnnotation;
16 18
 import org.openzen.zenscript.parser.expression.ParsedExpression;
17 19
 
@@ -32,8 +34,12 @@ public class ParsedStatementLock extends ParsedStatement {
32 34
 
33 35
 	@Override
34 36
 	public Statement compile(StatementScope scope) {
35
-		Expression object = this.object.compile(new ExpressionScope(scope)).eval();
36
-		Statement content = this.content.compile(scope);
37
-		return result(new LockStatement(position, object, content), scope);
37
+		try {
38
+			Expression object = this.object.compile(new ExpressionScope(scope)).eval();
39
+			Statement content = this.content.compile(scope);
40
+			return result(new LockStatement(position, object, content), scope);
41
+		} catch (CompileException ex) {
42
+			return result(new InvalidStatement(ex), scope);
43
+		}
38 44
 	}
39 45
 }

+ 0
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementReturn.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save