Skip to content

Commit 747b2c7

Browse files
committed
add variance test cases
1 parent 3e0246e commit 747b2c7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg-custom-args/fatal-warnings/enum-variance.scala:2:12 ------------------------------------------------
2+
2 | case Refl(f: T => T) // error: covariant T in contravariant position... enum case may require explicit type parameters
3+
| ^^^^^^^^^
4+
| covariant type T occurs in contravariant position in type T => T of value f
5+
| enum case class Refl may require explicit type parameters to resolve this issue
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enum View[+T]:
2+
case Refl(f: T => T) // error: covariant T in contravariant position... enum case may require explicit type parameters
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package asts
2+
3+
enum Ast[-T >: Null]:
4+
case DefDef()
5+
6+
trait AstImpl[T >: Null]:
7+
type Ast = asts.Ast[T]
8+
type DefDef = Ast.DefDef[T]
9+
end AstImpl
10+
11+
object untpd extends AstImpl[Null]:
12+
13+
def DefDef(ast: Ast): DefDef = ast match
14+
case ast: DefDef => ast
15+
16+
end untpd

tests/pos/enum-variance.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Animal
2+
class Dog extends Animal
3+
4+
enum Opt[+T]:
5+
case Sm(t: T)
6+
case None
7+
8+
val smDog: Opt.Sm[Dog] = new Opt.Sm(Dog())
9+
val smAnimal: Opt.Sm[Animal] = smDog
10+
11+
enum Show[-T]:
12+
case Refl(op: T => String)
13+
14+
def show(t: T): String = this match
15+
case Refl(op) => op(t)
16+
17+
val reflAnimal: Show.Refl[Animal] = new Show.Refl(_.toString)
18+
val reflDog: Show.Refl[Dog] = reflAnimal

0 commit comments

Comments
 (0)