aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2019-01-25 11:27:32 -0800
committerLiam Miller-Cushon <cushon@google.com>2019-01-28 21:35:35 -0800
commitc612ef98e6c5bf5eef7859289a52cf9f5711f62c (patch)
treeff7388692beda96c5bfa4e3df1ea3e9923fee6a1
parent5f06705a31526d605fe767c46d0b10974a454d43 (diff)
downloadturbine-c612ef98e6c5bf5eef7859289a52cf9f5711f62c.tar.gz
Don't crash on type variables used as qualifiers in const exprs
MOE_MIGRATED_REVID=230937580
-rw-r--r--java/com/google/turbine/binder/ConstEvaluator.java4
-rw-r--r--javatests/com/google/turbine/binder/BinderErrorTest.java16
2 files changed, 20 insertions, 0 deletions
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java
index 6db85e1..cfc63fc 100644
--- a/java/com/google/turbine/binder/ConstEvaluator.java
+++ b/java/com/google/turbine/binder/ConstEvaluator.java
@@ -35,6 +35,7 @@ import com.google.turbine.binder.lookup.MemberImportIndex;
import com.google.turbine.binder.lookup.Scope;
import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.binder.sym.FieldSymbol;
+import com.google.turbine.binder.sym.Symbol;
import com.google.turbine.diag.SourceFile;
import com.google.turbine.diag.TurbineError;
import com.google.turbine.diag.TurbineError.ErrorKind;
@@ -203,6 +204,9 @@ public strictfp class ConstEvaluator {
if (result == null) {
throw error(classTy.position(), ErrorKind.CANNOT_RESOLVE, flat.peekFirst());
}
+ if (result.sym().symKind() != Symbol.Kind.CLASS) {
+ throw error(classTy.position(), ErrorKind.UNEXPECTED_TYPE_PARAMETER, flat.peekFirst());
+ }
ClassSymbol classSym = (ClassSymbol) result.sym();
for (Ident bit : result.remaining()) {
classSym = resolveNext(classTy.position(), classSym, bit);
diff --git a/javatests/com/google/turbine/binder/BinderErrorTest.java b/javatests/com/google/turbine/binder/BinderErrorTest.java
index 5e6b9f1..de2237d 100644
--- a/javatests/com/google/turbine/binder/BinderErrorTest.java
+++ b/javatests/com/google/turbine/binder/BinderErrorTest.java
@@ -519,6 +519,22 @@ public class BinderErrorTest {
" ^",
},
},
+ {
+ {
+ "@interface Param {",
+ " Class<?> type();",
+ "}",
+ "class Foo<T> {",
+ " @Param(type = T.class)",
+ " public void bar() {}",
+ "}",
+ },
+ {
+ "<>:5: error: unexpected type parameter T",
+ " @Param(type = T.class)",
+ " ^",
+ },
+ },
};
return Arrays.asList((Object[][]) testCases);
}