File: magic_identifier_file_conflicting.swift.gyb

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (104 lines) | stat: -rw-r--r-- 6,333 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 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 should 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)