Disallow importing from the same soy file.
GITHUB_BREAKING_CHANGES=N/A
@@ -61,6 +61,8 @@ abstract class ImportsPass {
SoyErrorKind.of("Import ''{0}'' conflicts with namespace for global ''{1}''.");
private static final SoyErrorKind IMPORT_CONFLICTS_WITH_TYPE_NAME =
SoyErrorKind.of("Import ''{0}'' conflicts with a builtin type of the same name.");
+ private static final SoyErrorKind IMPORT_SAME_FILE =
+ SoyErrorKind.of("Importing from the same file is not allowed.");
/**
* Visits a Soy file, validating its imports and updating the file's {@link
@@ -135,6 +137,11 @@ abstract class ImportsPass {
return;
}
+ if (node.getPath().equals(file.getFilePath().path())) {
+ errorReporter.report(node.getPathSourceLocation(), IMPORT_SAME_FILE);
+ return;
+ }
+
if (!importExists(node.getImportType(), node.getPath())) {
String nodePath = node.getPath();
ImmutableSet<String> validPaths = getValidImportPathsForType(node.getImportType());
