Skip to content

pattern matching does not wlways check outer #2

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

Closed
scabug opened this issue Aug 27, 2007 · 7 comments
Closed

pattern matching does not wlways check outer #2

scabug opened this issue Aug 27, 2007 · 7 comments
Assignees

Comments

@scabug
Copy link

scabug commented Aug 27, 2007

Aladdin: [http://scala-webapps.epfl.ch/bugtracking/bugs/displayItem.do?id=1159 bug 1159]

== Code ==

class Outer {
  case class Foo(x: int, y: int) {
    override def equals(other: Any) = other match {
      case Outer.this.Foo(`x`, `y`) => true
      case _ => false
    }
  }
}

object Test extends Application {
  val o1 = new Outer
  val o2 = new Outer
  val x: Any = o1.Foo(1, 2)
  val y: Any = o2.Foo(1, 2)
  println(x equals y)
  x match {
    case o2.Foo(x, y) => println("error 1")
    case o1.Foo(x, y) => println("OK")
    case _ => println("error 2")
  }
}

== What happened ==

true
OK

== What expected ==

false
OK
@scabug
Copy link
Author

scabug commented Aug 27, 2007

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

@scabug
Copy link
Author

scabug commented Aug 27, 2007

@burakemir said:
(meta) haha, if you don't assign to anybody, trac picks "dubochet" (/meta)

This ticket is from open aladdin bug #1159.

@scabug
Copy link
Author

scabug commented Aug 29, 2007

@dubochet said:
When fixing this, it's tricky not too insert too many outer tests. For instance, if other' in equals' had type Outer.this.Foo' instead of Any', there should be no outer test, because we know statically that the outer pointers must be the same (if not, the types would not work out) [martin]

@scabug
Copy link
Author

scabug commented Aug 29, 2007

@burakemir said:
I'd rather uniformly generate outer tests everywhere and have a later phase figure out which tests are necessary and which are not. There is already magic that translates isInstanceOf[A with B] to isInstanceOf[A]&&isInstanceOf[B], these things are independent of pattern matching.

Alternatively, I would like to have an API method to which I can give source and destination type as well as the context (in the form of the owner symbol), and it figures out what I have to do.

My present outer generation is hard to understand (for myself and others), because pattern matching happens at the same time as explicitouter. Putting additional logic in there is not going to make it simpler.

@scabug
Copy link
Author

scabug commented Aug 29, 2007

@odersky said:
I have added a method needsOuterTest to Types.scala. If you call it from the pattern matcher, this should do the trick.

@scabug
Copy link
Author

scabug commented Sep 1, 2007

@burakemir said:
fixed in tags R_2_6_0-RC2 in r12757
fixed in trunk, r12758

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone 2.6.0 deleted

@scabug scabug closed this as completed May 18, 2011
This was referenced Apr 6, 2017
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