-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recursive case types: test cases for variance
Summary: Apparently, variance works! Differential Revision: D62753981 fbshipit-source-id: 10fab958d60dcef037f5623ae3b00098c3dddd5b
- Loading branch information
1 parent
0e7a43c
commit e99c5e4
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
hphp/hack/test/typecheck/case_type/recursive/variance1.php
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,11 @@ | ||
<?hh | ||
<<file: __EnableUnstableFeatures('case_types')>> | ||
|
||
final class Cov<+T> {} | ||
|
||
final class Contra<-T> {} | ||
|
||
case type A<+T> = Cov<A<T>>; // ok | ||
case type B<-T> = Cov<B<T>>; // ok | ||
case type D<-T> = Contra<D<T>>; // nok | ||
case type E<+T> = Contra<E<T>>; // nok |
46 changes: 46 additions & 0 deletions
46
hphp/hack/test/typecheck/case_type/recursive/variance1.php.exp
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,46 @@ | ||
ERROR: File "variance1.php", line 8, characters 11-11: | ||
Cyclic type definition (Typing[4014]) | ||
File "variance1.php", line 8, characters 23-26: | ||
Cyclic use is here | ||
ERROR: File "variance1.php", line 9, characters 11-11: | ||
Cyclic type definition (Typing[4014]) | ||
File "variance1.php", line 9, characters 23-26: | ||
Cyclic use is here | ||
ERROR: File "variance1.php", line 10, characters 11-11: | ||
Cyclic type definition (Typing[4014]) | ||
File "variance1.php", line 10, characters 26-29: | ||
Cyclic use is here | ||
ERROR: File "variance1.php", line 11, characters 11-11: | ||
Cyclic type definition (Typing[4014]) | ||
File "variance1.php", line 11, characters 26-29: | ||
Cyclic use is here | ||
ERROR: File "variance1.php", line 11, characters 28-28: | ||
Illegal usage of a covariant type parameter (Typing[4120]) | ||
File "variance1.php", line 11, characters 14-14: | ||
This is where the parameter was declared as covariant `+` | ||
File "variance1.php", line 11, characters 28-28: | ||
This position is contravariant (-) because it is the composition of (+)(-)(+) | ||
The rest of the error messages decomposes the inference of the variance. | ||
Check out this link if you don't understand what this is about: | ||
http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) | ||
File "variance1.php", line 11, characters 28-28: | ||
(+) This type parameter was declared as covariant (+) (cf 'E') | ||
File "variance1.php", line 11, characters 26-29: | ||
(-) This type parameter was declared as contravariant (-) (cf 'Contra') | ||
File "variance1.php", line 11, characters 19-30: | ||
(+) Aliased types are covariant | ||
ERROR: File "variance1.php", line 10, characters 28-28: | ||
Illegal usage of a contravariant type parameter (Typing[4121]) | ||
File "variance1.php", line 10, characters 14-14: | ||
This is where the parameter was declared as contravariant `-` | ||
File "variance1.php", line 10, characters 28-28: | ||
This position is covariant (+) because it is the composition of (-)(-)(+) | ||
The rest of the error messages decomposes the inference of the variance. | ||
Check out this link if you don't understand what this is about: | ||
http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) | ||
File "variance1.php", line 10, characters 28-28: | ||
(-) This type parameter was declared as contravariant (-) (cf 'D') | ||
File "variance1.php", line 10, characters 26-29: | ||
(-) This type parameter was declared as contravariant (-) (cf 'Contra') | ||
File "variance1.php", line 10, characters 19-30: | ||
(+) Aliased types are covariant |