Skip to content
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

views inference on non-accessible selection #6074

Closed
scabug opened this issue Jul 12, 2012 · 7 comments
Closed

views inference on non-accessible selection #6074

scabug opened this issue Jul 12, 2012 · 7 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jul 12, 2012

Spec:

 Views are applied in three situations.
 [...]
 2. In a selection e.m with e of type T, if the selector m does not denote a member of T.
     In this case, a view v is searched [...]

However, the implementation also searches for an implicit conversion when m denotes a
non-accessible member of T:

  scala> class A { protected def f = 101 }
  scala> class B { def f = "duckflow" }
  scala> object T {
       |   implicit def a2b(a: A): B = new B
       | 
       |   def t = (new A).f
       | }
  scala> T.t
  res0: String = duckflow

Even worse, the same happens for constructors! An expression "new T()" is represented
as a tree Apply(Selelct(New(T), ), ())

If the constructor is private, an conversion to "?{def : ?}" is searched! This generates
invalid trees and crashes later phases, e.g. NamesDefaults, #5231, but also GenICode,
as in the following example:

  scala> class A private () { }
  scala> class B { }
  scala> object T {
       |   implicit def a2b(a: A): B = null
       |   def t = new A()
       | }
  
  Unexpected New(TypeTree(class $read$$iw$$iw$A)/$line7.$read$$iw$$iw$A) received in icode.
  [...]
    at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:43)
    at scala.tools.nsc.Global.abort(Global.scala:228)
    at scala.tools.nsc.interpreter.IMain$$anon$1.scala$tools$nsc$interpreter$ReplGlobal$$super$abort(IMain.scala:277)
    at scala.tools.nsc.interpreter.ReplGlobal$class.abort(ReplGlobal.scala:21)
    at scala.tools.nsc.interpreter.IMain$$anon$1.abort(IMain.scala:277)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:708)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1201)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1199)
    at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
@scabug
Copy link
Author

scabug commented Jul 12, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6074?orig=1
Reporter: @lrytz
See #5231

@scabug
Copy link
Author

scabug commented Jul 12, 2012

@lrytz said:
two more examples that crash the compiler in different places, probably all due to this bug. the first one is actually #5231:

object T {
  def m = new ConfigBuilder()
  implicit def build( cb: ConfigBuilder ) : Config = null
}

class Config(x: Int)

class ConfigBuilder private ()  { }

Second one, crash in Symbols.info

object Config {
  def apply() : ConfigBuilder = new ConfigBuilder()
  implicit def build( cb: ConfigBuilder ) : Config = cb.build
}

final class Config private[Client]( val clientID: Int )

final class ConfigBuilder {
  var clientID: Int = 0
  def build : Config = new Config( clientID )
}

@scabug
Copy link
Author

scabug commented Jul 12, 2012

@paulp said:
Not the same bug, but reminiscent of #4645, #4685, #4707, #4987, #5058.

@scabug
Copy link
Author

scabug commented Jul 24, 2012

@lrytz said:
update spec. fix the constructor case (don't search a view there). adaptToMember.

@scabug
Copy link
Author

scabug commented Jul 24, 2012

@lrytz said:
hasMethodMatching should always be false for <init>

@scabug
Copy link
Author

scabug commented Aug 4, 2012

@lrytz said:
fixed in scala/scala#1051

spec clarification in scala/scala-dist#50

@scabug scabug closed this as completed Aug 4, 2012
@scabug
Copy link
Author

scabug commented Sep 23, 2013

@retronym said:
Spec update merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants