Skip to content

Fix #9568: Disallow partially undefined types as byname anchors #9575

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 2 commits into from
Aug 17, 2020
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
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,9 @@ object Implicits:
candidates += Candidate(ref, ckind, level)

if considerExtension then
val tryExtension = tryCandidate(extensionOnly = true)
companionRefs.foreach(tryExtension)
companionRefs.foreach(tryCandidate(extensionOnly = true))
if refs.nonEmpty then
val tryGiven = tryCandidate(extensionOnly = false)
refs.foreach(tryGiven)
refs.foreach(tryCandidate(extensionOnly = false))
candidates.toList
}
}
Expand Down Expand Up @@ -1373,6 +1371,7 @@ trait Implicits:
if cand1.ref eq cand.ref then
lazy val wildTp = wildApprox(tp.widenExpr)
if belowByname && (wildTp <:< wildPt) then
fullyDefinedType(tp, "by-name implicit parameter", span)
false
else if prev.typeSize > ptSize || prev.coveringSet != ptCoveringSet then
loop(outer, tp.isByName || belowByname)
Expand Down
4 changes: 1 addition & 3 deletions tests/neg/i3452.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ object Test {
implicit def case1[F[_]](implicit t: => TC[F[Any]]): TC[Tuple2K[[_] =>> Any, F, Any]] = ???
implicit def case2[A, F[_]](implicit r: TC[F[Any]]): TC[A] = ???

// Disabled because it leads to an infinite loop in implicit search
// this is probably the same issue as https://github.com/lampepfl/dotty/issues/9568
// implicitly[TC[Int]] // was: error
implicitly[TC[Int]] // typechecks because we infer F := Nothing (should we avoid inferring Nothing for higher-kinded types?)
}

object Test1 {
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i9568.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Error: tests/neg/i9568.scala:13:10 ----------------------------------------------------------------------------------
13 | blaMonad.foo(bla) // error: diverges
| ^
|no implicit argument of type => Monad[([_$3] =>> Any)] was found for parameter ev of method blaMonad in object Test.
|I found:
|
| Test.blaMonad[Nothing, S](Test.blaMonad[F, S])
|
|But method blaMonad in object Test does not match type => Monad[Nothing].
14 changes: 14 additions & 0 deletions tests/neg/i9568.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait Monad[F[_]] {
def foo[A](fa: F[A]): Unit = {}
}

class Bla[F[_], A]

object Test {
type Id[A] = A

val bla: Bla[Id, Unit] = ???
implicit def blaMonad[F[_], S](implicit ev: => Monad[F]): Monad[({type L[X] = Bla[F, X]})#L] = ???

blaMonad.foo(bla) // error: diverges
}
25 changes: 25 additions & 0 deletions tests/pos/i9568.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
trait Monad[F[_]] {
def foo[A](fa: F[A]): Unit = {}
}

class Bla[F[_], A]

object Test1 {
type Id[A] = A

val bla: Bla[Id, Unit] = ???
implicit def blaMonad[F[_]: Monad, S]: Monad[({type L[X] = Bla[F, X]})#L] = ???
implicit def idMonad: Monad[Id] = ???

blaMonad.foo(bla) // does not diverge
}

object Test2 {
type Id[A] = A

val bla: Bla[Id, Unit] = ???
implicit def blaMonad[F[_], S](implicit ev: => Monad[F]): Monad[({type L[X] = Bla[F, X]})#L] = ???
implicit def idMonad: Monad[Id] = ???

blaMonad.foo(bla) // does not diverge
}