Added error checking for references that reference the same file along

with 3 tests,
This commit is contained in:
unknown 2014-09-25 08:44:46 -07:00
parent db0a223b1e
commit cafa481843
9 changed files with 65 additions and 5 deletions

View File

@ -340,6 +340,7 @@ module ts {
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
A_file_cannot_have_a_reference_to_itself: { code: 5006, category: DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." },

View File

@ -1355,6 +1355,10 @@
"category": "Error",
"code": 5001
},
"A file cannot have a reference to itself.": {
"category": "Error",
"code": 5006
},
"Cannot find the common subdirectory path for the input files.": {
"category": "Error",
"code": 5009

View File

@ -3828,11 +3828,18 @@ module ts {
errorAtPos(start, length, Diagnostics.Invalid_reference_directive_syntax);
}
else {
referencedFiles.push({
pos: range.pos,
end: range.end,
filename: matchResult[3]
});
var basePath = getDirectoryPath(file.filename);
var referenceFilename = normalizePath(combinePaths(basePath, matchResult[3]));
if (file.filename === referenceFilename) {
errorAtPos(range.pos, range.end - range.pos, Diagnostics.A_file_cannot_have_a_reference_to_itself);
}
else {
referencedFiles.push({
pos: range.pos,
end: range.end,
filename: matchResult[3]
});
}
}
}
}

View File

@ -0,0 +1,11 @@
tests/cases/compiler/selfReferencingFile.ts(1,1): error TS5006: A file cannot have a reference to itself.
==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ====
///<reference path='selfReferencingFile.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5006: A file cannot have a reference to itself.
class selfReferencingFile {
}

View File

@ -0,0 +1,11 @@
tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found.
==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ====
///<reference path='../selfReferencingFile2.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6053: File 'selfReferencingFile2.ts' not found.
class selfReferencingFile2 {
}

View File

@ -0,0 +1,11 @@
tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS5006: A file cannot have a reference to itself.
==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ====
///<reference path='./selfReferencingFile3.ts'/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5006: A file cannot have a reference to itself.
class selfReferencingFile3 {
}

View File

@ -0,0 +1,5 @@
///<reference path='selfReferencingFile.ts'/>
class selfReferencingFile {
}

View File

@ -0,0 +1,5 @@
///<reference path='../selfReferencingFile2.ts'/>
class selfReferencingFile2 {
}

View File

@ -0,0 +1,5 @@
///<reference path='./selfReferencingFile3.ts'/>
class selfReferencingFile3 {
}