Skip to content

Commit

Permalink
recursive case types: test cases for variance
Browse files Browse the repository at this point in the history
Summary: Apparently, variance works!

Differential Revision: D62753981

fbshipit-source-id: 10fab958d60dcef037f5623ae3b00098c3dddd5b
  • Loading branch information
Catherine Gasnier authored and facebook-github-bot committed Sep 17, 2024
1 parent 0e7a43c commit e99c5e4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hphp/hack/test/typecheck/case_type/recursive/variance1.php
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 hphp/hack/test/typecheck/case_type/recursive/variance1.php.exp
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

0 comments on commit e99c5e4

Please sign in to comment.