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

Import at the same level as a class definition not considered for implicit view within constructor #4141

Closed
scabug opened this issue Jan 9, 2011 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jan 9, 2011

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===

bug.scala

object test {
  object A
  trait B

  object Conv {
    implicit def a2b(a: A.type): B = new B {}
  }

  import Conv._

  class Boo(a: B = A) {          // fails

    def this(a: Any, b: B = A) = // fails
      this(new B {})

    def method(b: B = A) = ()    // okay
    A: B                         // okay
  }
}

=== What is the expected behavior? ===

Compilation success.

=== What do you see instead? ===

scalac -d target/ src/main/scala/bug.scala 
src/main/scala/bug.scala:11: error: type mismatch;
 found   : test.A.type (with underlying type object test.A)
 required: test.B
  class Boo(a: B = A) {          // fails
                   ^
src/main/scala/bug.scala:13: error: type mismatch;
 found   : test.A.type (with underlying type object test.A)
 required: test.B
    def this(a: Any, b: B = A) = // fails
                            ^
two errors found

=== Additional information ===

Source: http://stackoverflow.com/questions/4640634/weird-bug-related-to-implicit-conversions-on-default-contructor-parameters

=== What versions of the following are you using? ===

  • Scala: 2.8.1 / 2.9.0-SNAPSHOT
@scabug
Copy link
Author

scabug commented Jan 9, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4141?orig=1
Reporter: @retronym

@scabug
Copy link
Author

scabug commented Jan 10, 2011

@retronym said:
s/within constructor/within constructor default parameter/

@scabug
Copy link
Author

scabug commented Jan 26, 2011

@adriaanm said:
(In r24093) closes #3619, #4141. need to exclude implicits from class C in calls to superconstructor from C's constructor.
replaced the epic outer.outer.outer by something more robust that goes to the context corresponding to the enclosing class

nextOuter determines which context is searched next for implicits (after this, which contributes newImplicits below)
in most cases, it is simply the outer context
if we're owned by a constructor, the actual current context and the conceptual context are different when it comes to scoping:
the current conceptual scope is the context enclosing the blocks that represent the constructor body
(TODO: why is there more than one such block in the outer chain?)

review by odersky, extempore

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

No branches or pull requests

2 participants