diff options
author | Colin Cross <ccross@android.com> | 2021-07-16 18:34:42 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-07-16 18:34:42 +0000 |
commit | d6118c099b71aac0100cce47f7e5f16cbbfb897e (patch) | |
tree | f3960bf41b61a8f29eb4ddc3bdc03da8c15976ab /java/com/google/turbine/binder/TypeBinder.java | |
parent | 2a4cb0ec252bf941a985428a368ca7a81707e7d6 (diff) | |
parent | 88adfa1e21a5c8e806580f8a1edc6f3669d0d167 (diff) | |
download | turbine-d6118c099b71aac0100cce47f7e5f16cbbfb897e.tar.gz |
Merge remote-tracking branch 'aosp/upstream-main' am: 54111aedb4 am: aef8ef46bb am: 88adfa1e21
Original change: https://android-review.googlesource.com/c/platform/external/turbine/+/1768552
Change-Id: I8a13cdf80543ff6aae316168500f03801efc7b0c
Diffstat (limited to 'java/com/google/turbine/binder/TypeBinder.java')
-rw-r--r-- | java/com/google/turbine/binder/TypeBinder.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/java/com/google/turbine/binder/TypeBinder.java b/java/com/google/turbine/binder/TypeBinder.java index 7b01856..a28acd9 100644 --- a/java/com/google/turbine/binder/TypeBinder.java +++ b/java/com/google/turbine/binder/TypeBinder.java @@ -16,6 +16,8 @@ package com.google.turbine.binder; +import static java.util.Objects.requireNonNull; + import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -54,6 +56,7 @@ import com.google.turbine.tree.TurbineModifier; import com.google.turbine.type.AnnoInfo; import com.google.turbine.type.Type; import com.google.turbine.type.Type.IntersectionTy; +import com.google.turbine.types.Deannotate; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashSet; @@ -394,7 +397,8 @@ public class TypeBinder { ImmutableList<Tree.TyParam> trees, CompoundScope scope, Map<String, TyVarSymbol> symbols) { ImmutableMap.Builder<TyVarSymbol, TyVarInfo> result = ImmutableMap.builder(); for (Tree.TyParam tree : trees) { - TyVarSymbol sym = symbols.get(tree.name().value()); + // `symbols` is constructed to guarantee the requireNonNull call is safe. + TyVarSymbol sym = requireNonNull(symbols.get(tree.name().value())); ImmutableList.Builder<Type> bounds = ImmutableList.builder(); for (Tree bound : tree.bounds()) { bounds.add(bindTy(scope, bound)); @@ -493,6 +497,9 @@ public class TypeBinder { == 0) { access |= TurbineFlag.ACC_ABSTRACT; } + if ((access & TurbineFlag.ACC_FINAL) == TurbineFlag.ACC_FINAL) { + log.error(t.position(), ErrorKind.UNEXPECTED_MODIFIER, TurbineModifier.FINAL); + } break; case ENUM: if (name.equals("<init>")) { @@ -618,7 +625,14 @@ public class TypeBinder { case WILD_TY: return bindWildTy(scope, (Tree.WildTy) ty); default: - return bindTy(scope, ty); + Type result = bindTy(scope, ty); + if (result.tyKind().equals(Type.TyKind.PRIM_TY)) { + // Omit type annotations when printing the type in the diagnostic, since they're + // irrelevant and could be invalid if there were deferred errors. + // TODO(cushon): consider ensuring this is done for all diagnostics that mention types + log.error(ty.position(), ErrorKind.UNEXPECTED_TYPE, Deannotate.deannotate(result)); + } + return result; } } |