|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %gyb -D TEMPDIR=%t %s > %t/magic_identifier_file_conflicting.swift |
| 3 | + |
| 4 | +// We want to check both the diagnostics and the SIL output. |
| 5 | +// 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 |
| 6 | + |
| 7 | +%{ |
| 8 | +TEMPDIR_ESC = TEMPDIR.replace('\\', '\\\\') |
| 9 | +def fixit_loc(start_col, orig_suffix): |
| 10 | + """ |
| 11 | + Computes a "start-end" string for a fix-it replacing a string literal which |
| 12 | + starts at start_col and joins orig_suffix to TEMPDIR with a slash. |
| 13 | + """ |
| 14 | + original = '"{0}/{1}"'.format(TEMPDIR, orig_suffix) |
| 15 | + end_col = start_col + len(original) |
| 16 | + return '{0}-{1}'.format(start_col, end_col) |
| 17 | +}% |
| 18 | + |
| 19 | +// |
| 20 | +// Same name as a physical file |
| 21 | +// |
| 22 | + |
| 23 | +// There should be no warning for the exact same path. |
| 24 | +// no-warning |
| 25 | +#sourceLocation(file: "${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift", line: 10) |
| 26 | +#sourceLocation() |
| 27 | + |
| 28 | +// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/magic_identifier_file_conflicting.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 29 | +// 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"}} |
| 30 | +#sourceLocation(file: "${TEMPDIR_ESC}/other_path_b/magic_identifier_file_conflicting.swift", line: 20) |
| 31 | +#sourceLocation() |
| 32 | + |
| 33 | +// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/magic_identifier_file_conflicting.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 34 | +// expected-note@+1 {{change file in '#sourceLocation' to '${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift'}} {{23-64="${TEMPDIR_ESC}/magic_identifier_file_conflicting.swift"}} |
| 35 | +#sourceLocation(file: "magic_identifier_file_conflicting.swift", line: 30) |
| 36 | +#sourceLocation() |
| 37 | + |
| 38 | +// |
| 39 | +// No physical file with the same name |
| 40 | +// |
| 41 | + |
| 42 | +// There shoud be no warning for a purely virtual file. |
| 43 | +// no-warning |
| 44 | +#sourceLocation(file: "other_file_a.swift", line: 40) |
| 45 | +#sourceLocation() |
| 46 | + |
| 47 | +// Even if you use it twice. |
| 48 | +// no-warning |
| 49 | +#sourceLocation(file: "other_file_a.swift", line: 50) |
| 50 | +#sourceLocation() |
| 51 | + |
| 52 | +// But there should be warnings for different-path, same-name virtual files. |
| 53 | +// The lexicographically first path should be treated as canonical--we diagnose |
| 54 | +// but don't offer a fix-it. |
| 55 | +// expected-warning@+1 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 56 | +#sourceLocation(file: "first/other_file_b.swift", line: 60) |
| 57 | +#sourceLocation() |
| 58 | + |
| 59 | +// Subsequent paths should fix-it to the first one. |
| 60 | +// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 61 | +// expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-50="first/other_file_b.swift"}} |
| 62 | +#sourceLocation(file: "second/other_file_b.swift", line: 70) |
| 63 | +#sourceLocation() |
| 64 | + |
| 65 | +// Even if there's more than one. |
| 66 | +// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 67 | +// expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-49="first/other_file_b.swift"}} |
| 68 | +#sourceLocation(file: "third/other_file_b.swift", line: 80) |
| 69 | +#sourceLocation() |
| 70 | + |
| 71 | +// Even if one is duplicated. |
| 72 | +// expected-warning@+2 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_b.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 73 | +// expected-note@+1 {{change file in '#sourceLocation' to 'first/other_file_b.swift'}} {{23-49="first/other_file_b.swift"}} |
| 74 | +#sourceLocation(file: "third/other_file_b.swift", line: 90) |
| 75 | +#sourceLocation() |
| 76 | + |
| 77 | +// We should diagnose cross-file conflicts. |
| 78 | +// expected-warning@+1 {{'#sourceLocation' directive produces '#file' string of 'Foo/other_file_c.swift', which conflicts with '#file' strings produced by other paths in the module}} |
| 79 | +#sourceLocation(file: "first/other_file_c.swift", line: 100) |
| 80 | +#sourceLocation() |
| 81 | + |
| 82 | +// |
| 83 | +// Check '#file' => '#filePath' mapping table |
| 84 | +// |
| 85 | + |
| 86 | +// CHECK-LABEL: // Mappings from '#file' to '#filePath': |
| 87 | +// 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' |
| 88 | +// 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) |
| 89 | +// CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting.swift' => 'magic_identifier_file_conflicting.swift' (alternate) |
| 90 | +// CHECK-NEXT: // 'Foo/magic_identifier_file_conflicting_other.swift' => 'SOURCE_DIR{{[/\\]}}test{{[/\\]}}SILGen{{[/\\]}}Inputs{{[/\\]}}magic_identifier_file_conflicting_other.swift' |
| 91 | +// CHECK-NEXT: // 'Foo/other_file_a.swift' => 'other_file_a.swift' |
| 92 | +// CHECK-NEXT: // 'Foo/other_file_b.swift' => 'first/other_file_b.swift' |
| 93 | +// CHECK-NEXT: // 'Foo/other_file_b.swift' => 'second/other_file_b.swift' (alternate) |
| 94 | +// CHECK-NEXT: // 'Foo/other_file_b.swift' => 'third/other_file_b.swift' (alternate) |
| 95 | +// CHECK-NEXT: // 'Foo/other_file_c.swift' => 'first/other_file_c.swift' |
| 96 | +// CHECK-NEXT: // 'Foo/other_file_c.swift' => 'second/other_file_c.swift' (alternate) |
0 commit comments