Skip to content

Commit ce0e3f2

Browse files
authored
Merge pull request #6107 from dotty-staging/fix-#6036
Fix #6036: Restrict inferred parents for new {...}
2 parents a7b67c4 + 3fa35dc commit ce0e3f2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ object Inferencing {
150150
tree
151151
}
152152

153+
def isSkolemFree(tp: Type)(implicit ctx: Context): Boolean =
154+
!tp.existsPart(_.isInstanceOf[SkolemType])
155+
153156
/** Derive information about a pattern type by comparing it with some variant of the
154157
* static scrutinee type. We have the following situation in case of a (dynamic) pattern match:
155158
*

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ class Typer extends Namer
520520
def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final) && !tp.isRef(defn.AnyClass)
521521
if (templ1.parents.isEmpty &&
522522
isFullyDefined(pt, ForceDegree.noBottom) &&
523+
isSkolemFree(pt) &&
523524
isEligible(pt.underlyingClassRef(refinementOK = false)))
524525
templ1 = cpy.Template(templ)(parents = untpd.TypeTree(pt) :: Nil)
525526
templ1.parents foreach {

tests/neg/i6036.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A { class AProxy }
2+
3+
object B {
4+
inline def head(a: A)(code: => a.AProxy): Unit = code
5+
head(new A)(new {}) // error: found: Object {...} required: ?1.AProxy
6+
7+
val a = new A
8+
head(a)(new a.AProxy{}) // ok
9+
}

0 commit comments

Comments
 (0)