Skip to content

parameter type inference with type paramers broken #1803

Closed

Description

@scabug

the type infered for parameters of an overriding method do not refer to the right type parameter symbol (skolemized / deSkolemized).

lamppc26:~ luc$$ workspace/scala/build/quick/bin/scala -Xexperimental -uniqid
Welcome to Scala version (unknown) (Java HotSpot(TM) Client VM, Java 1.5.0_16).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class A { def foo[A](a: A) = a }
defined class A

scala> class B extends A { override def foo[A](b) = b }
<console>:5: error: type mismatch;
 found   : ASI-10818
 required: ASI-10819
       class B extends A { override def foo[A](b) = b }
                                                    ^

Activity

  1. scabug commented on Mar 18, 2009

    @scabug
    Author
  2. scabug commented on Feb 6, 2015

    @scabug
    Author

    kenji yoshida said:
    resolved?

    $ scala -Yinfer-argument-types -uniqid
    Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_72).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> class A { def foo[A](a: A) = a }
    defined class A
    
    scala> class B extends A { override def foo[A](b) = b }
    defined class B
  3. added this to the Backlog milestone on Apr 6, 2017
  4. spangaer commented on Apr 5, 2018

    @spangaer

    That one is indeed fixed but another one is broken.
    When generic parameters are assigned in deriving class. Methods using those generic parameters used to support type inference when overridden (Scala 2.11), but now no longer do (Scala 2.12).

    Scala 2.11

    C:\Windows\System32>scala -Yinfer-argument-types
    Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> trait X[T] {  def doit(t: T): T}
    defined trait X
    
    scala> class Y extends X[String] {  override def doit(s) =    s}
    defined class Y

    Scala 2.12

    D:\data\downloads\java\scala\scala-2.12.5\scala-2.12.5\bin>scala -Yinfer-argument-types
    Welcome to Scala 2.12.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
    Type in expressions for evaluation. Or try :help.
    
    scala> trait X[T] {  def doit(t: T): T}
    defined trait X
    
    scala> class Y extends X[String] {  override def doit(s) =    s}
    <console>:12: error: type mismatch;
     found   : T
     required: String
           class Y extends X[String] {  override def doit(s) =    s}
                                                                  ^
  5. hrhino commented on Apr 5, 2018

    @hrhino

    I think this feature may be on the chopping block (as part of scala/scala-dev#430), so this might become a won't-fix soon.

  6. adriaanm commented on Apr 5, 2018

    @adriaanm
    Contributor

    Yes, this will go away, sorry.

  7. spangaer commented on Apr 5, 2018

    @spangaer

    Faster response than expected.

    Well, I got this in via -Xexperimental which I had put in in the process of enabling Java 8 lambda bytecode in 2.11. Wasn't aware of the matter, but built quite a bit of code base that relied on it :(

    Ok, out it goes. Hope you get a chance to respond to my comment in the referred issue equally fast ;).

  8. deleted a comment from scabug on Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions