Skip to content

Commit e1aecf1

Browse files
committed
Merge pull request #149 from dotty-staging/fix/#148
fix/#148
2 parents bdb6361 + 65658a4 commit e1aecf1

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

src/dotty/tools/dotc/transform/Splitter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Splitter extends TreeTransform {
7070
}
7171

7272
def isStructuralSelect(tp: Type): Boolean = tp.stripTypeVar match {
73-
case tp: RefinedType => tp.refinedName == name || isStructuralSelect(tp)
73+
case tp: RefinedType => tp.refinedName == name || isStructuralSelect(tp.parent)
7474
case tp: TypeProxy => isStructuralSelect(tp.underlying)
7575
case AndType(tp1, tp2) => isStructuralSelect(tp1) || isStructuralSelect(tp2)
7676
case _ => false

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class tests extends CompilerTest {
7575
defaultOptions = noCheckOptions)
7676
// -Ycheck fails because there are structural types involving higher-kinded types.
7777
// these are illegal, but are tested only later.
78+
@Test def neg_zoo = compileFile(negDir, "zoo", xerrors = 1)
7879
@Test def neg_t1192_legalPrefix = compileFile(negDir, "t1192", xerrors = 1)
7980
@Test def neg_tailcall_t1672b = compileFile(negDir, "tailcall/t1672b", xerrors = 6)
8081
@Test def neg_tailcall_t3275 = compileFile(negDir, "tailcall/t3275", xerrors = 1)

tests/neg/zoo.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
object Test {
2+
type Meat = {
3+
type IsMeat = Any
4+
}
5+
type Grass = {
6+
type IsGrass = Any
7+
}
8+
type Animal = {
9+
type Food
10+
def eats(food: Food): Unit
11+
def gets: Food
12+
}
13+
type Cow = {
14+
type IsMeat = Any
15+
type Food <: Grass
16+
def eats(food: Grass): Unit
17+
def gets: Grass
18+
}
19+
type Lion = {
20+
type Food = Meat
21+
def eats(food: Meat): Unit
22+
def gets: Meat
23+
}
24+
def newMeat: Meat = new {
25+
type IsMeat = Any
26+
}
27+
def newGrass: Grass = new {
28+
type IsGrass = Any
29+
}
30+
def newCow: Cow = new {
31+
type IsMeat = Any
32+
type Food = Grass
33+
def eats(food: Grass) = ()
34+
def gets = newGrass
35+
}
36+
def newLion: Lion = new {
37+
type Food = Meat
38+
def eats(food: Meat) = ()
39+
def gets = newMeat
40+
}
41+
val milka = newCow
42+
val leo = newLion
43+
leo.eats(milka) // structural select not supported
44+
}

tests/pos/zoo.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
object Test {
2+
type Meat = {
3+
type IsMeat = Any
4+
}
5+
type Grass = {
6+
type IsGrass = Any
7+
}
8+
type Animal = {
9+
type Food
10+
def eats(food: Food): Unit
11+
def gets: Food
12+
}
13+
type Cow = {
14+
type IsMeat = Any
15+
type Food <: Grass
16+
def eats(food: Grass): Unit
17+
def gets: Grass
18+
}
19+
type Lion = {
20+
type Food = Meat
21+
def eats(food: Meat): Unit
22+
def gets: Meat
23+
}
24+
def newMeat: Meat = new {
25+
type IsMeat = Any
26+
}
27+
def newGrass: Grass = new {
28+
type IsGrass = Any
29+
}
30+
def newCow: Cow = new {
31+
type IsMeat = Any
32+
type Food = Grass
33+
def eats(food: Grass) = ()
34+
def gets = newGrass
35+
}
36+
def newLion: Lion = new {
37+
type Food = Meat
38+
def eats(food: Meat) = ()
39+
def gets = newMeat
40+
}
41+
val milka = newCow
42+
val leo = newLion
43+
//leo.eats(milka) // structural select not supported
44+
}

0 commit comments

Comments
 (0)