Skip to content

Commit

Permalink
Move unresolved type errors to compile time when SA is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter12345 committed Mar 28, 2024
1 parent 7f8657d commit 2a1b2a1
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/main/java/com/laytonsmith/core/functions/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.Script;
import com.laytonsmith.core.compiler.FileOptions;
import com.laytonsmith.core.compiler.analysis.StaticAnalysis;
import com.laytonsmith.core.constructs.CBareString;
import com.laytonsmith.core.constructs.CBracket;
import com.laytonsmith.core.constructs.CClassType;
Expand Down Expand Up @@ -745,7 +746,7 @@ public ParseTree postParseRewrite(ParseTree ast, Environment env,
@api
@noprofile
@hide("This is only used internally by the compiler.")
public static class __type_ref__ extends DummyFunction {
public static class __type_ref__ extends DummyFunction implements Optimizable {

public static final String NAME = "__type_ref__";

Expand Down Expand Up @@ -786,6 +787,29 @@ public static ParseTree createASTNode(String typeName, Target t, FileOptions fil
node.addChild(new ParseTree(new CString(typeName, t), fileOptions, true));
return node;
}

@Override
public Set<OptimizationOption> optimizationOptions() {
return EnumSet.of(OptimizationOption.OPTIMIZE_DYNAMIC);
}

@Override
public ParseTree optimizeDynamic(Target t, Environment env,
Set<Class<? extends Environment.EnvironmentImpl>> envs,
List<ParseTree> children, FileOptions fileOptions)
throws ConfigCompileException, ConfigRuntimeException {

/*
* With static analysis enabled, the typechecker has already taken care of this AST node.
* Until MethodScript supports user types, we know that custom types cannot be resolved regardless of the
* outcome of static analysis. So we can generate an exception here until user type support is added.
*/
if(!StaticAnalysis.enabled()) {
throw new ConfigCompileException(
"\"" + children.get(0).getData().val() + "\" cannot be resolved to a type.", t);
}
return null;
}
}

@api
Expand Down

0 comments on commit 2a1b2a1

Please sign in to comment.