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

Fix #2732: Allow wildcards in SAM types #3347

Closed
wants to merge 1 commit into from

Conversation

smarter
Copy link
Member

@smarter smarter commented Oct 18, 2017

The isInstantiable test as written is incorrect:
Given tp = java.util.function.Function[String, _ <: String], we will have:
tref = skolem TermRef with underlying info tp
selfType = java.util.function.Function[String, tref#R] (because of the asSeenFrom)
tref <:< selfType is false, because tref.underlying is
just tp and its return type parameter is a bounded wildcard, not a reference with
tref as a prefix.
In any case, I cannot think of a case where this function should return
false, and no test failed when I removed it. So I'm removing it until
someone can come up with a counter-example.

The `isInstantiable` test as written is incorrect:
Given tp = `java.util.function.Function[String, _ <: String]`, we will have:
    tref = skolem TermRef with underlying info `tp`
    selfType = `java.util.function.Function[String, tref#R]` (because of the `asSeenFrom`)
`tref <:< selfType` is false, because `tref.underlying` is
just `tp` and its return type parameter is a bounded wildcard, not a reference with
`tref` as a prefix.
In any case, I cannot think of a case where this function should return
false, and no test failed when I removed it. So I'm removing it until
someone can come up with a counter-example.
@odersky
Copy link
Contributor

odersky commented Oct 24, 2017

Here's a test:

class B {
  def f = 1
}

trait A { self: B =>

  def g1(x: Int): Int
  def g2 = g1(f)

}

object Test extends App {

  val x: A = (y: Int) => y + y

  println(x.g2)

}

With master this gives:

-- [E007] Type Mismatch Error: ../neg/i3347.scala:14:30 ------------------------
14 |  val x: A = (y: Int) => y + y
   |                              ^
   |                              found:    Int => Int
   |                              required: A
   |        

With this PR it compiles but we get a ClassCast exception at runtime.

~/workspace/dotty/tests/pos> java Test
Exception in thread "main" java.lang.ExceptionInInitializerError
at Test.main(i3347.scala)
Caused by: java.lang.ClassCastException: Test$$$Lambda$10/425918570 cannot be cast to B
at A.g2(i3347.scala:8)
at Test$.(i3347.scala:16)
at Test$.(i3347.scala)
... 1 more

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the test shows, we can't drop isInstantiatable

@smarter
Copy link
Member Author

smarter commented Oct 26, 2017

Indeed. Can you think of a way to fix isInstantiable ? Maybe we could use a TypeMap to rewrite Function[String, _ <: String] to Function[String, String] before calling .narrow, but that's not very nice.

@liufengyun
Copy link
Contributor

test performance please

(meta test of the bench infrastructure)

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

performance test failed:

Error line number: 19

[check /data/workspace/bench/logs/pull-3347-10-26-18.18.out for more information]

@odersky
Copy link
Contributor

odersky commented Oct 29, 2017

Indeed. Can you think of a way to fix isInstantiable?

For the moment it's too much of a context switch for me to think of a fix.

@smarter
Copy link
Member Author

smarter commented Mar 21, 2018

Superceded by #4152

@smarter smarter closed this Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants