blob: 19efcc1d7a4416552bfb54b04c1677ea6344b790 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
object Test {
type Meat = {
type IsMeat = Any
}
type Grass = {
type IsGrass = Any
}
type Animal = {
type Food
def eats(food: Food): Unit // error
def gets: Food // error
}
type Cow = {
type IsMeat = Any
type Food <: Grass
def eats(food: Grass): Unit // error
def gets: Grass // error
}
type Lion = {
type Food = Meat
def eats(food: Meat): Unit // error
def gets: Meat // error
}
def newMeat: Meat = new {
type IsMeat = Any
}
def newGrass: Grass = new {
type IsGrass = Any
}
def newCow: Cow = new {
type IsMeat = Any
type Food = Grass
def eats(food: Grass) = ()
def gets = newGrass
}
def newLion: Lion = new {
type Food = Meat
def eats(food: Meat) = ()
def gets = newMeat
}
val milka = newCow
val leo = newLion
leo.eats(milka) // structural select not supported
}
|