Skip to content
Permalink
Browse files

Improve bare string detection and limit to one warning per file

  • Loading branch information...
PseudoKnight committed Oct 1, 2019
1 parent 6c596d9 commit 7350575e13b91ea3ba9df997edb6773d81c8a216
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
@@ -1762,11 +1762,11 @@ public static ParseTree compile(TokenStream stream, Environment environment,
procs.add(new ArrayList<>());
processKeywords(tree, compilerErrors);
optimizeAutoconcats(tree, environment, envs, compilerErrors);
checkLinearComponents(tree, environment, compilerErrors);
optimize(tree, environment, envs, procs, compilerErrors);
link(tree, compilerErrors, envs);
checkLabels(tree, compilerErrors);
checkBreaks(tree, compilerErrors);
checkLinearComponents(tree, environment, compilerErrors);
if(!compilerErrors.isEmpty()) {
if(compilerErrors.size() == 1) {
// Just throw the one CCE
@@ -1786,14 +1786,15 @@ public static ParseTree compile(TokenStream stream, Environment environment,
private static void checkLinearComponents(ParseTree tree, Environment env,
Set<ConfigCompileException> compilerErrors) {
for(ParseTree m : tree.getAllNodes()) {
if(m.getData() instanceof CBareString) {
if(m.getData().isInstanceOf(CBareString.TYPE)) {
if(m.getFileOptions().isStrict()) {
compilerErrors.add(new ConfigCompileException("Use of bare strings in strict mode is not"
+ " allowed.", m.getTarget()));
} else {
env.getEnv(CompilerEnvironment.class).addCompilerWarning(m.getFileOptions(),
new CompilerWarning("Use of bare string", m.getTarget(),
FileOptions.SuppressWarning.UseBareStrings));
return; // for now, only one warning per file
}
}
}

0 comments on commit 7350575

Please sign in to comment.
You can’t perform that action at this time.