Skip to content

Commit 20818af

Browse files
committed
Fix #7425: Handle nullary/parameterless conflicts in infoMeet
We did handle ():T & (=> T), but not (=> T) & ():T.
1 parent 42e3ad4 commit 20818af

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,18 @@ object Denotations {
653653
case ExprType(rtp1) =>
654654
tp2 match {
655655
case ExprType(rtp2) => ExprType(rtp1 & rtp2)
656-
case _ => rtp1 & tp2
656+
case _ => infoMeet(rtp1, tp2, sym1, sym2, safeIntersection)
657657
}
658658
case _ =>
659-
try tp1 & tp2.widenExpr
660-
catch {
661-
case ex: Throwable =>
662-
println(i"error for meet: $tp1 &&& $tp2, ${tp1.getClass}, ${tp2.getClass}")
663-
throw ex
664-
}
659+
tp2 match
660+
case _: MethodType | _: PolyType =>
661+
mergeConflict(sym1, sym2, tp1, tp2)
662+
case _ =>
663+
try tp1 & tp2.widenExpr
664+
catch
665+
case ex: Throwable =>
666+
println(i"error for meet: $tp1 &&& $tp2, ${tp1.getClass}, ${tp2.getClass}")
667+
throw ex
665668
}
666669

667670
/** Normally, `tp1 | tp2`.

tests/neg/i7425.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class C { def f: Int = 0 }
2+
3+
trait D { def f(): Int = 0 }
4+
5+
def foo1(x: C & D) = x.f // error: method f must be called with () argument
6+
def foo2(x: C | D) = x.f // error: value f is not a member of C | D
7+
def foo3(x: D & C) = x.f // ok
8+
def foo4(x: D | C) = x.f // error: value f is not a member of D | C
9+
def foo5(x: C & D) = x.f() // ok
10+
def foo6(x: C | D) = x.f() // error: value f is not a member of C | D
11+
def foo7(x: D & C) = x.f() // error: method f in class C does not take parameters
12+
def foo8(x: D | C) = x.f() // error: value f is not a member of D | C

0 commit comments

Comments
 (0)