Skip to content

Commit c7e2222

Browse files
committed
[Sema] Diagnose passing integer to non-integer type parameter
This was previously missed, though would have been diagnosed later as a requirement failure.
1 parent cc9a9b0 commit c7e2222

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ namespace {
792792
return false;
793793
}
794794

795+
if (secondType->is<IntegerType>())
796+
return false;
797+
795798
return true;
796799
}
797800

test/Sema/inlinearray.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ let e: InlineArray<2, _> = [1] // expected-error {{expected '2' elements in inli
99

1010
let f: InlineArray<_, Int> = ["hello"] // expected-error {{cannot convert value of type 'String' to expected element type 'Int'}}
1111

12+
let g: InlineArray<1, 1> // expected-error {{cannot use value type '1' for generic argument 'Element'}}
13+
1214
func takeVectorOf2<T>(_: InlineArray<2, T>) {}
1315

1416
takeVectorOf2([1, 2]) // Ok

test/Sema/value_generics.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ func h(_: (Int, 123)) {} // expected-error {{expected type}}
6666
func i(_: () -> 123) {} // expected-error {{expected type}}
6767
func j(_: (A<123>) -> ()) {} // OK
6868
func k(_: some 123) {} // expected-error {{expected parameter type following ':'}}
69-
func l(_: GenericWithIntParam<123, Int>) {} // expected-error {{cannot pass type 'Int' as a value for generic value 'N'}}
69+
func l(_: GenericWithIntParam<123, Int>) {}
70+
// expected-error@-1 {{cannot pass type 'Int' as a value for generic value 'N'}}
71+
// expected-error@-2 {{cannot use value type '123' for generic argument 'T'}}
7072
func m(_: GenericWithIntParam<Int, 123>) {} // OK
7173

7274
typealias One = 1 // expected-error {{expected type in type alias declaration}}

0 commit comments

Comments
 (0)