Skip to content

Commit d64d5cb

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 22d01f3 commit d64d5cb

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
@@ -793,6 +793,9 @@ namespace {
793793
return false;
794794
}
795795

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

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)