Skip to content

Generalize "Don't approximate a type using Nothing as prefix" #23628

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6507,7 +6507,7 @@ object Types extends TypeUtils {
protected def range(lo: Type, hi: Type): Type =
if variance > 0 then hi
else if variance < 0 then
if (lo eq defn.NothingType) && hi.hasSimpleKind then
if (lo eq defn.NothingType) then
// Approximate by Nothing & hi instead of just Nothing, in case the
// approximated type is used as the prefix of another type (this would
// lead to a type with a `NoDenotation` denot and a possible
Expand All @@ -6518,8 +6518,14 @@ object Types extends TypeUtils {
// example if Nothing is the type of a parameter being depended on in
// a MethodType)
//
// Test case in tests/pos/i23530.scala
AndType(lo, hi)
// Test case in tests/pos/i23530.scala (and tests/pos/i23627.scala for
// the higher-kinded case which requires eta-expansion)
hi.etaExpand match
case expandedHi: HKTypeLambda =>
expandedHi.derivedLambdaType(resType = AndType(lo, expandedHi.resType))
case _ =>
// simple-kinded case
AndType(lo, hi)
else
lo
else if lo `eq` hi then lo
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i23627.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait TestContainer:
trait TestPath[T]:
type AbsMember

extension (path: TestPath[?])
infix def ext(color: path.AbsMember): Unit = ???
infix def ext(other: Int): Unit = ???

object Repro:
val dc2: TestContainer = ???
import dc2.TestPath

def transition(path: TestPath[?])(using DummyImplicit): TestPath[?] = ???

def test: Unit =
val di: TestPath[?] = ???
// error
val z1 = transition(di).ext(1)
Loading