Skip to content

Fix #11466: disallow implicit conversion for <init> #11478

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
Feb 24, 2021
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2994,7 +2994,7 @@ class Typer extends Namer
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))

// try an implicit conversion or given extension
if ctx.mode.is(Mode.ImplicitsEnabled) && qual.tpe.isValueType then
if ctx.mode.is(Mode.ImplicitsEnabled) && !tree.name.isConstructorName && qual.tpe.isValueType then
trace(i"try insert impl on qualifier $tree $pt") {
val selProto = selectionProto
inferView(qual, selProto) match
Expand Down
16 changes: 16 additions & 0 deletions tests/neg/i11466.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import scala.language.implicitConversions

trait TripleEqualsSupport:
class Equalizer[L](val leftSide: L)
def convertToEqualizer[T](left: T): Equalizer[T]

trait TripleEquals extends TripleEqualsSupport:
implicit override def convertToEqualizer[T](left: T): Equalizer[T] = new Equalizer(left)

class GraphDB[Id]:
class Node private[GraphDB](val id: Id)

object GraphDBSpec extends TripleEquals:
object graph extends GraphDB[String]
import graph.Node
val m = new Node("Alice") // error