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

getClass.getName doesn't return a real java.lang.String with correct replace and replaceAll behaviour #4884

Closed
scabug opened this issue Aug 7, 2011 · 6 comments
Assignees

Comments

@scabug
Copy link

scabug commented Aug 7, 2011

getClass.getName doesn't return a real java.lang.String because replace and replaceAll don't work properly

scala> class A {
     |  val b = new B
     |  class B {
     |  val c = new C
     |  class C {
     |  }
     |  }
     |  }
defined class A

scala> val a = new A
a: A = A@19e0bcf

scala> val c = a.b.c
c: a.b.C = A$B$C@90dbc4

scala> c.getClass.getName.replace("$","#")
res60: java.lang.String = #line92.#read##iw##iw#A#B#C

scala> c.getClass.getName.replaceAll("[$]","#")
res61: java.lang.String = #line92.#read##iw##iw#A#B#C

Expected behaviour:

scala> "A$B$C".replace("$","#")
res0: java.lang.String = A#B#C

scala> "A$B$C".replaceAll("[$]","#")
res1: java.lang.String = A#B#C
@scabug
Copy link
Author

scabug commented Aug 7, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4884?orig=1
Reporter: DaveScala (davescala)
Affected Versions: 2.9.0-1
Attachments:

  • name.scala (created on Aug 7, 2011 12:59:35 PM UTC, 564 bytes)

@scabug
Copy link
Author

scabug commented Aug 7, 2011

DaveScala (davescala) said:
{{{
scala> class A {
| val b = new B
| class B {
| val c = new C
| class C {
| }
| }
| }
defined class A
}}}

@scabug
Copy link
Author

scabug commented Aug 7, 2011

@soc said (edited on Aug 7, 2011 12:02:47 PM UTC):
This has to do with the name mangling of the REPL.

Could you make your bug report actually readable? I think the tables and the other stuff are not intended ...

Can you verify it when compiling?

@scabug
Copy link
Author

scabug commented Aug 7, 2011

DaveScala (davescala) said:
The table formatting does Jira. What is the preformatted code? Prbably the vertical bars from the REPL causes Jira making a table

I compiled it and then it works, but still it is not good that REPL does something different.

C:\scala-2.9.1.RC1\examples\name>scala Main
c.getClass: class A$B$C
c.getClass.getName: A$B$C
c.toString: A$B$C@1bfa475
c.isInstanceOf[A#B#C]: true
c.getClass.getName.replace("$","#"): A#B#C
c.getClass.getName.replaceAll("[$]","#"): A#B#C

@scabug
Copy link
Author

scabug commented Aug 7, 2011

DaveScala (davescala) said (edited on Aug 7, 2011 1:00:59 PM UTC):
File name.scala is attached

@scabug
Copy link
Author

scabug commented Aug 7, 2011

@paulp said:
The repl is not, and cannot be, an environment with perfect fidelity to compiler semantics.

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