Allow aliases collisions when identical to proto imports. Makes multipass proto tricorder more resilient.
GITHUB_BREAKING_CHANGES=N/A
@@ -23,6 +23,8 @@ import com.google.template.soy.logging.ValidatedLoggingConfig;
import com.google.template.soy.shared.SoyGeneralOptions;
import com.google.template.soy.soytree.AliasDeclaration;
import com.google.template.soy.soytree.SoyFileNode;
+import com.google.template.soy.types.SoyProtoEnumType;
+import com.google.template.soy.types.SoyProtoType;
import com.google.template.soy.types.SoyType;
import com.google.template.soy.types.SoyTypeRegistry;
@@ -66,9 +68,13 @@ final class ValidateAliasesPass implements CompilerFilePass {
SoyType type = registry.getType(alias.alias().identifier());
// When running with a dummy type provider that parses all types as unknown, ignore that.
if (type != null && type.getKind() != SoyType.Kind.UNKNOWN) {
+ // Temporarily, while we migrate all proto aliases to imports, ignore aliases that are
+ // identical to proto imports. They don't conflict and Tricorder will remove the aliases.
+ if (!alias.namespace().identifier().equals(getFqProtoName(type))) {
errorReporter.report(
alias.alias().location(), ALIAS_CONFLICTS_WITH_TYPE_NAME, alias.alias());
}
+ }
String conflictingNamespacedType =
registry.findTypeWithMatchingNamespace(alias.alias().identifier());
if (conflictingNamespacedType != null) {
@@ -90,4 +96,14 @@ final class ValidateAliasesPass implements CompilerFilePass {
}
}
}
+
+ private static String getFqProtoName(SoyType type) {
+ if (type instanceof SoyProtoType) {
+ return ((SoyProtoType) type).getDescriptor().getFullName();
+ } else if (type instanceof SoyProtoEnumType) {
+ return ((SoyProtoEnumType) type).getDescriptor().getFullName();
+ } else {
+ return null;
+ }
+ }
}
