-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check type parameter bounds for default values and named types (#…
…919) Closes partially #614 ### Summary of Changes * Ensure default values of type parameters respect their upper bound. * Ensure type arguments of named types respect the upper bound of the corresponding type parameter.
- Loading branch information
1 parent
4302ca6
commit 7003ea6
Showing
5 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ang/tests/resources/validation/types/checking/default values/with type parameters.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package tests.validation.types.checking.defaultValues | ||
|
||
class SomeClass<T1, T2 sub Number>( | ||
// $TEST$ no error r"Expected type .* but got .*\." | ||
p1: T1 = »true«, | ||
// $TEST$ no error r"Expected type .* but got .*\." | ||
p2: T1 = »1«, | ||
// $TEST$ error "Expected type 'T2' but got 'literal<"">'." | ||
p3: T2 = »""«, | ||
) | ||
|
||
fun someFunction<T1, T2 sub Number>( | ||
// $TEST$ no error r"Expected type .* but got .*\." | ||
p1: T1 = »true«, | ||
// $TEST$ no error r"Expected type .* but got .*\." | ||
p2: T1 = »1«, | ||
// $TEST$ error "Expected type 'T2' but got 'literal<"">'." | ||
p3: T2 = »""«, | ||
) |
57 changes: 57 additions & 0 deletions
57
...resources/validation/types/checking/type parameter bounds for default values/main.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package tests.validation.types.checking.typeParameterBoundsForDefaultValues | ||
|
||
class C1< | ||
T1 sub Any, | ||
// $TEST$ error "Expected type 'Number' but got 'T1'." | ||
T2 sub Number = »T1«, | ||
// $TEST$ error "Expected type 'Number' but got 'Any'." | ||
T3 sub Number = »Any«, | ||
// $TEST$ error "Expected type 'T1' but got 'Any'." | ||
T4 sub T1 = »Any«, | ||
> | ||
class C2< | ||
T1 sub Number, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T2 sub Number = »T1«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T3 sub Number = »Number«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T4 sub T1 = »T1«, | ||
> | ||
class C3< | ||
T1 sub Int, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T2 sub Number = »T1«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T3 sub Number = »Int«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T4 sub T1 = »Nothing«, | ||
> | ||
|
||
@Pure fun f1< | ||
T1 sub Any, | ||
// $TEST$ error "Expected type 'Number' but got 'T1'." | ||
T2 sub Number = »T1«, | ||
// $TEST$ error "Expected type 'Number' but got 'Any'." | ||
T3 sub Number = »Any«, | ||
// $TEST$ error "Expected type 'T1' but got 'Any'." | ||
T4 sub T1 = »Any«, | ||
>() | ||
@Pure fun f2< | ||
T1 sub Number, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T2 sub Number = »T1«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T3 sub Number = »Number«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T4 sub T1 = »T1«, | ||
>() | ||
@Pure fun f3< | ||
T1 sub Int, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T2 sub Number = »T1«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T3 sub Number = »Int«, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
T4 sub T1 = »Nothing«, | ||
>() |
29 changes: 29 additions & 0 deletions
29
...ts/resources/validation/types/checking/type parameter bounds for named types/main.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tests.validation.types.checking.typeParameterBoundsForNamedTypes | ||
|
||
class C1<T1> | ||
class C2<T1 sub Number> | ||
class C3<T1, T2 sub T1> | ||
|
||
@Pure fun f( | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
a1: C1<»Any?«>, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
a2: C1<T1 = »Any?«>, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
a3: C1<Unknown = »Any?«>, | ||
|
||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
b1: C2<»Number«>, | ||
// $TEST$ error "Expected type 'Number' but got 'String'." | ||
b2: C2<»String«>, | ||
|
||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
c1: C3<»Number«, »Number«>, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
c2: C3<»Number«, »Int«>, | ||
// $TEST$ no error r"Expected type '.*' but got '.*'\." | ||
// $TEST$ error "Expected type 'Int' but got 'Number'." | ||
c3: C3<»Int«, »Number«>, | ||
) |