aboutsummaryrefslogtreecommitdiff
path: root/java/com/google/turbine
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2018-05-03 13:28:14 -0700
committerLiam Miller-Cushon <cushon@google.com>2018-06-12 19:44:44 -0700
commit7e5cf9a597e2ea0737b989ef46aa09d29d7fea3d (patch)
treebe2d1aacad078b053ecff755c2c45e9948dc6f94 /java/com/google/turbine
parentc1f59b1b0c4327c186ee84e4087b3926affd3302 (diff)
downloadturbine-7e5cf9a597e2ea0737b989ef46aa09d29d7fea3d.tar.gz
Fix a crash reporting missing symbols in constant expressions
MOE_MIGRATED_REVID=195301603
Diffstat (limited to 'java/com/google/turbine')
-rw-r--r--java/com/google/turbine/binder/ConstEvaluator.java17
-rw-r--r--java/com/google/turbine/parse/ConstExpressionParser.java12
2 files changed, 16 insertions, 13 deletions
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java
index ad9d117..1952839 100644
--- a/java/com/google/turbine/binder/ConstEvaluator.java
+++ b/java/com/google/turbine/binder/ConstEvaluator.java
@@ -203,17 +203,20 @@ public strictfp class ConstEvaluator {
}
ClassSymbol classSym = (ClassSymbol) result.sym();
for (String bit : result.remaining()) {
- classSym = Resolve.resolve(env, origin, classSym, bit);
- if (classSym == null) {
- throw error(
- classTy.position(),
- ErrorKind.SYMBOL_NOT_FOUND,
- new ClassSymbol(classSym.binaryName() + '$' + bit));
- }
+ classSym = resolveNext(classTy.position(), classSym, bit);
}
return classSym;
}
+ private ClassSymbol resolveNext(int position, ClassSymbol sym, String bit) {
+ ClassSymbol next = Resolve.resolve(env, origin, sym, bit);
+ if (next == null) {
+ throw error(
+ position, ErrorKind.SYMBOL_NOT_FOUND, new ClassSymbol(sym.binaryName() + '$' + bit));
+ }
+ return next;
+ }
+
/** Evaluates a reference to another constant variable. */
Const evalConstVar(ConstVarName t) {
FieldInfo field = resolveField(t);
diff --git a/java/com/google/turbine/parse/ConstExpressionParser.java b/java/com/google/turbine/parse/ConstExpressionParser.java
index bd644dc..51f3128 100644
--- a/java/com/google/turbine/parse/ConstExpressionParser.java
+++ b/java/com/google/turbine/parse/ConstExpressionParser.java
@@ -220,7 +220,8 @@ public class ConstExpressionParser {
case NOT:
case TILDE:
case IDENT:
- return new Tree.TypeCast(position, asClassTy(cvar.name()), primary(false));
+ return new Tree.TypeCast(
+ position, asClassTy(cvar.position(), cvar.name()), primary(false));
default:
return expr;
}
@@ -229,12 +230,11 @@ public class ConstExpressionParser {
}
}
- private ClassTy asClassTy(ImmutableList<String> names) {
+ private static ClassTy asClassTy(int pos, ImmutableList<String> names) {
ClassTy cty = null;
for (String bit : names) {
cty =
- new ClassTy(
- position, Optional.fromNullable(cty), bit, ImmutableList.of(), ImmutableList.of());
+ new ClassTy(pos, Optional.fromNullable(cty), bit, ImmutableList.of(), ImmutableList.of());
}
return cty;
}
@@ -425,7 +425,7 @@ public class ConstExpressionParser {
bits.add(lexer.stringValue());
eat();
if (token == Token.LBRACK) {
- return finishClassLiteral(pos, asClassTy(bits.build()));
+ return finishClassLiteral(pos, asClassTy(pos, bits.build()));
}
while (token == Token.DOT) {
eat();
@@ -436,7 +436,7 @@ public class ConstExpressionParser {
case CLASS:
// TODO(cushon): only allow in annotations?
eat();
- return new Tree.ClassLiteral(pos, asClassTy(bits.build()));
+ return new Tree.ClassLiteral(pos, asClassTy(pos, bits.build()));
default:
return null;
}