forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-resolution-overload.swift
79 lines (62 loc) · 2.58 KB
/
import-resolution-overload.swift
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
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/overload_intFunctions.swift
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/overload_boolFunctions.swift
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/overload_vars.swift
// RUN: %target-swift-frontend -parse %s -I %t -sdk "" -verify
// RUN: not %target-swift-frontend -dump-ast %s -I %t -sdk "" > %t.astdump 2>&1
// RUN: FileCheck %s < %t.astdump
import overload_intFunctions
import overload_boolFunctions
import overload_vars
import var overload_vars.scopedVar
import func overload_boolFunctions.scopedFunction
struct LocalType {}
func something(obj: LocalType) -> LocalType { return obj } // expected-note {{found this candidate}}
func something(a: Int, _ b: Int, _ c: Int) -> () {} // expected-note {{found this candidate}}
var _ : Bool = something(true)
var _ : Int = something(1)
var _ : (Int, Int) = something(1, 2)
var _ : LocalType = something(LocalType())
var _ : () = something(1, 2, 3)
something = 42 // expected-error {{ambiguous reference to member 'something'}}
let ambValue = ambiguousWithVar // no-warning - var preferred
let ambValueChecked: Int = ambValue
ambiguousWithVar = 42 // no-warning
ambiguousWithVar(true) // no-warning
var localVar : Bool
localVar = false
localVar = 42 // expected-error {{cannot assign value of type 'Int' to type 'Bool'}}
localVar(42) // expected-error {{cannot call value of non-function type 'Bool'}}
var _ : localVar // should still work
_ = scopedVar // no-warning
scopedVar(42) // expected-error {{cannot call value of non-function type 'Int'}}
var _ : Bool = scopedFunction(true)
var _ : Int = scopedFunction(42)
scopedFunction = 42 // expected-error {{ambiguous reference to member 'scopedFunction'}}
// FIXME: Should be an error -- a type name and a function cannot overload.
var _ : Int = TypeNameWins(42)
TypeNameWins = 42 // expected-error {{ambiguous reference to member 'TypeNameWins'}}
var _ : TypeNameWins // no-warning
// rdar://problem/21739333
protocol HasFooSub : HasFoo { }
extension HasFooSub {
var foo: Int { return 0 }
}
// CHECK-LABEL: func_decl "testHasFooSub(_:)"
func testHasFooSub(hfs: HasFooSub) -> Int {
// CHECK: return_stmt
// CHECK-NOT: func_decl
// CHECK: member_ref_expr{{.*}}decl=overload_vars.(file).HasFoo.foo
return hfs.foo
}
extension HasBar {
var bar: Int { return 0 }
}
// CHECK-LABEL: func_decl "testHasBar(_:)"
func testHasBar(hb: HasBar) -> Int {
// CHECK: return_stmt
// CHECK-NOT: func_decl
// CHECK: member_ref_expr{{.*}}decl=overload_vars.(file).HasBar.bar
return hb.bar
}