| // RUN: %empty-directory(%t) |
| // RUN: %gyb -D TEMPDIR=%t %s > %t/magic_identifier_file_conflicting.swift |
| // RUN: %{python} -c "import io; import sys; t = io.open(sys.argv[1], 'r', encoding='utf-8').read().replace('\r\n', '\n'); io.open(sys.argv[1], 'w', encoding='utf-8', newline='\n').write(t)" %t/magic_identifier_file_conflicting.swift |
| |
| // We want to check both the diagnostics and the SIL output. |
| // RUN: %target-swift-emit-silgen -verify -emit-sorted-sil -enable-experimental-concise-pound-file -module-name Foo %t/magic_identifier_file_conflicting.swift %S/Inputs/magic_identifier_file_conflicting_other.swift | %FileCheck %s |
| |
| // FIXME: Make this test work on Windows. There's no fundamental reason it |
| // can't; we just need someone with a Windows machine to do it so we |
| // don't have a 30-minute debug cycle. |
| // UNSUPPORTED: OS=windows-msvc |
| |
| %{ |
| TEMPDIR_ESC = TEMPDIR.replace('\\', '\\\\') |
| |
| import os |
| def fixit_loc(start_col, orig_suffix): |
| """ |
| Computes a "start-end" string for a fix-it replacing a string literal which |
| starts at start_col and joins orig_suffix to TEMPDIR with a slash. |
| """ |
| original = '"{0}"'.format(os.path.join(TEMPDIR, orig_suffix)) |
| end_col = start_col + len(original) |
| return '{0}-{1}'.format(start_col, end_col) |
| }% |
| |
| // |
| // Same name as a physical file |
| // |
| |
| // There should be no warning for the exact same path. |
| // no-warning |
| #sourceLocation(file: "${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift", line: 10) |
| #sourceLocation() |
| |
| // expected-warning@+2 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/magic_identifier_file_conflicting.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| // expected-note@+1 {{change file in '#sourceLocation' to '${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift'}} {{${fixit_loc(23, "other_path_b/magic_identifier_file_conflicting.swift")}="${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift"}} |
| #sourceLocation(file: "${TEMPDIR_ESC}/other_path_b/magic_identifier_file_conflicting.swift", line: 20) |
| #sourceLocation() |
| |
| // expected-warning@+2 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/magic_identifier_file_conflicting.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| // expected-note@+1 {{change file in '#sourceLocation' to '${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift'}} {{23-64="${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift"}} |
| #sourceLocation(file: "magic_identifier_file_conflicting.swift", line: 30) |
| #sourceLocation() |
| |
| // |
| // No physical file with the same name |
| // |
| |
| // There shoud be no warning for a purely virtual file. |
| // no-warning |
| #sourceLocation(file: "other_file_a.swift", line: 40) |
| #sourceLocation() |
| |
| // Even if you use it twice. |
| // no-warning |
| #sourceLocation(file: "other_file_a.swift", line: 50) |
| #sourceLocation() |
| |
| // But there should be warnings for different-path, same-name virtual files. |
| // The lexicographically first path should be treated as canonical--we diagnose |
| // but don't offer a fix-it. |
| // expected-warning@+1 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/other_file_b.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| #sourceLocation(file: "first/other_file_b.swift", line: 60) |
| #sourceLocation() |
| |
| // Subsequent paths should fix-it to the first one. |
| // expected-warning@+2 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/other_file_b.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| // expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-50="first/other_file_b.swift"}} |
| #sourceLocation(file: "second/other_file_b.swift", line: 70) |
| #sourceLocation() |
| |
| // Even if there's more than one. |
| // expected-warning@+2 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/other_file_b.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| // expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-49="first/other_file_b.swift"}} |
| #sourceLocation(file: "third/other_file_b.swift", line: 80) |
| #sourceLocation() |
| |
| // Even if one is duplicated. |
| // expected-warning@+2 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/other_file_b.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| // expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-49="first/other_file_b.swift"}} |
| #sourceLocation(file: "third/other_file_b.swift", line: 90) |
| #sourceLocation() |
| |
| // We should diagnose cross-file conflicts. |
| // expected-warning@+1 {{'#sourceLocation' directive produces '#fileID' string of 'Foo/other_file_c.swift', which conflicts with '#fileID' strings produced by other paths in the module}} |
| #sourceLocation(file: "first/other_file_c.swift", line: 100) |
| #sourceLocation() |
| |
| // |
| // Check '#fileID' => '#filePath' mapping table |
| // |
| |
| // CHECK-LABEL: // Mappings from '#fileID' to '#filePath': |
| // CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'BUILD_DIR{{[/\\]}}test-{{[^/]+}}{{[/\\]}}SILGen{{[/\\]}}Output{{[/\\]}}magic_identifier_file_conflicting.swift.gyb.tmp{{[/\\]}}magic_identifier_file_conflicting.swift' |
| // CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'BUILD_DIR{{[/\\]}}test-{{[^/]+}}{{[/\\]}}SILGen{{[/\\]}}Output{{[/\\]}}magic_identifier_file_conflicting.swift.gyb.tmp{{[/\\]}}other_path_b{{[/\\]}}magic_identifier_file_conflicting.swift' (alternate) |
| // CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'magic_identifier_file_conflicting.swift' (alternate) |
| // CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting_other.swift' => 'SOURCE_DIR{{[/\\]}}test{{[/\\]}}SILGen{{[/\\]}}Inputs{{[/\\]}}magic_identifier_file_conflicting_other.swift' |
| // CHECK-NEXT: // 'Foo/other_file_a.swift' => 'other_file_a.swift' |
| // CHECK-NEXT: // 'Foo/other_file_b.swift' => 'first/other_file_b.swift' |
| // CHECK-NEXT: // 'Foo/other_file_b.swift' => 'second/other_file_b.swift' (alternate) |
| // CHECK-NEXT: // 'Foo/other_file_b.swift' => 'third/other_file_b.swift' (alternate) |
| // CHECK-NEXT: // 'Foo/other_file_c.swift' => 'first/other_file_c.swift' |
| // CHECK-NEXT: // 'Foo/other_file_c.swift' => 'second/other_file_c.swift' (alternate) |