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

@specialized and asInstanceOf doesn't work in REPL #9022

Closed
scabug opened this issue Dec 1, 2014 · 8 comments

Comments

@scabug
Copy link

commented Dec 1, 2014

def aaa[@specialized(Int) T] = (5.0).asInstanceOf[T]
``` works fine with scalac, but return TypeCastException in REPL, see http://stackoverflow.com/questions/27213616/why-specialized-annotation-doesnt-work-for-asinstanceof/27221875
@scabug

This comment has been minimized.

Copy link
Author

commented Dec 1, 2014

Imported From: https://issues.scala-lang.org/browse/SI-9022?orig=1
Reporter: Dmytro Kondratiuk (dk14)

@scabug

This comment has been minimized.

Copy link
Author

commented Dec 2, 2014

@som-snytt said:
Works when pasted together.

scala> :pa -raw
// Entering paste mode (ctrl-D to finish)

package a { object A { def aaa[@specialized(Int) T] = (5.0).doubleValue.asInstanceOf[T] }}
package b { object B { def f = a.A.aaa[Int] }}

// Exiting paste mode, now interpreting.

[[syntax trees at end of                     typer]] // <pastie>
package <empty> {
  package a {
    object A extends scala.AnyRef {
      def <init>(): a.A.type = {
        A.super.<init>();
        ()
      };
      def aaa[@specialized(scala.Int) T]: T = scala.this.Predef.double2Double(5.0).doubleValue().asInstanceOf[T]
    }
  };
  package b {
    object B extends scala.AnyRef {
      def <init>(): b.B.type = {
        B.super.<init>();
        ()
      };
      def f: Int = a.A.aaa[Int]
    }
  }
}

[[syntax trees at end of                   cleanup]] // <pastie>
package <empty> {
  package a {
    object A extends Object {
      def aaa(): Object = scala.Double.box(scala.this.Predef.double2Double(5.0).doubleValue());
      <specialized> def aaa$mIc$sp(): Int = scala.this.Predef.double2Double(5.0).doubleValue().toInt();
      def <init>(): a.A.type = {
        A.super.<init>();
        ()
      }
    }
  };
  package b {
    object B extends Object {
      def f(): Int = a.A.aaa$mIc$sp();
      def <init>(): b.B.type = {
        B.super.<init>();
        ()
      }
    }
  }
}


scala> :pa -raw
// Entering paste mode (ctrl-D to finish)

package c { object B { def f = a.A.aaa[Int] }}

// Exiting paste mode, now interpreting.

[[syntax trees at end of                     typer]] // <pastie>
package c {
  object B extends scala.AnyRef {
    def <init>(): c.B.type = {
      B.super.<init>();
      ()
    };
    def f: Int = a.A.aaa[Int]
  }
}

[[syntax trees at end of                   cleanup]] // <pastie>
package c {
  object B extends Object {
    def f(): Int = scala.Int.unbox(a.A.aaa());
    def <init>(): c.B.type = {
      B.super.<init>();
      ()
    }
  }
}
@scabug

This comment has been minimized.

Copy link
Author

commented Dec 2, 2014

Dmytro Kondratiuk (dk14) said:
Agree, but it also should work for object Aaa {def aaa[@specialized(Int) T] = (5.0).asInstanceOf[T]} at least from the user perspective; or show some warnings like "use :paste mode to call specialized method"

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 26, 2015

@adriaanm said:
Duplicate of #9089

@scabug scabug closed this Feb 26, 2015

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 26, 2015

Dmytro Kondratiuk (dk14) said:
this bug was created earlier

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 26, 2015

@adriaanm said:
It was, thank you! The issue is fixed, just to be clear.

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 27, 2015

@som-snytt said:
I can't believe I missed a chance to call a duplicate of #9089.

@scabug

This comment has been minimized.

Copy link
Author

commented Apr 20, 2015

Dmytro Kondratiuk (dk14) said:
no despair, there is plenty of issuеs to duplicate ))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.