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

Strange error when destructuring into a val or lazy val #7507

Closed
scabug opened this issue May 22, 2013 · 6 comments
Closed

Strange error when destructuring into a val or lazy val #7507

scabug opened this issue May 22, 2013 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 22, 2013

class Bar

abstract class Cake extends Slice {
  val bar: Bar
}

trait Slice { self: Cake =>
  import bar._
  lazy val Foo(x, y) = foo
  private case class Foo(x: Int, y: Int)
  private lazy val foo: Foo = ???
}
20:50 ~/Projects/210x/sandbox (2.10.x)$ s
Test.scala:9: error: not found: value x$1
  lazy val Foo(x, y) = foo
               ^
Test.scala:9: error: not found: value x$1
  lazy val Foo(x, y) = foo
                  ^
two errors found
@scabug
Copy link
Author

scabug commented May 22, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7507?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.1

@scabug
Copy link
Author

scabug commented May 22, 2013

@paulp said (edited on May 22, 2013 10:19:17 PM UTC):
Minimized.

abstract class Cake extends Slice { }

trait Slice { self: Cake =>
  import java.lang.String // any import will do!
  val Tuple2(x, y) = ((1, 2))
}

@scabug
Copy link
Author

scabug commented May 23, 2013

@retronym said (edited on May 23, 2013 6:54:11 AM UTC):
After a little more whittling, it turns out to be a name lookup/access problem, unrelated to the pattern matcher.

trait Cake extends Slice

trait Slice { self: Cake =>    // must have self type that extends `Slice`
  private[this] val bippy = () // must be private[this]
  bippy
}

@scabug
Copy link
Author

scabug commented May 23, 2013

@retronym said (edited on May 23, 2013 7:07:49 AM UTC):
It hinges on the following condition in findMember:

if (excl == 0L &&
      (// omit PRIVATE LOCALS unless selector class is contained in class owning the def.
    (bcs eq bcs0) ||
    (flags & PrivateLocal) != PrivateLocal ||
    (bcs0.head.hasTransOwner(bcs.head)))) {

    // this = Slice.this.type
    // bcs  = List(trait Cake, trait Slice, class Object, class Any)
    // bcs0 = List(trait Slice, class Object, class Any)
    // <Cake>.hasTransOwner(<Slice) == false

@scabug
Copy link
Author

scabug commented May 23, 2013

@retronym said:
Here's my proposed fix: retronym/scala@scala:2.10.x...ticket/7507

@scabug
Copy link
Author

scabug commented May 30, 2013

@retronym said:
scala/scala#2609

@scabug scabug closed this as completed Jun 4, 2013
@scabug scabug added this to the 2.10.3-RC1 milestone Apr 7, 2017
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