Skip to content

Fix #6036: Restrict inferred parents for new {...} #6107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ object Inferencing {
tree
}

def isSkolemFree(tp: Type)(implicit ctx: Context): Boolean =
!tp.existsPart(_.isInstanceOf[SkolemType])

/** Derive information about a pattern type by comparing it with some variant of the
* static scrutinee type. We have the following situation in case of a (dynamic) pattern match:
*
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ class Typer extends Namer
def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final) && !tp.isRef(defn.AnyClass)
if (templ1.parents.isEmpty &&
isFullyDefined(pt, ForceDegree.noBottom) &&
isSkolemFree(pt) &&
isEligible(pt.underlyingClassRef(refinementOK = false)))
templ1 = cpy.Template(templ)(parents = untpd.TypeTree(pt) :: Nil)
templ1.parents foreach {
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i6036.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class A { class AProxy }

object B {
inline def head(a: A)(code: => a.AProxy): Unit = code
head(new A)(new {}) // error: found: Object {...} required: ?1.AProxy

val a = new A
head(a)(new a.AProxy{}) // ok
}