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

TraversableLike stringPrefix broken for inner classes #9019

Closed
scabug opened this issue Nov 29, 2014 · 8 comments
Closed

TraversableLike stringPrefix broken for inner classes #9019

scabug opened this issue Nov 29, 2014 · 8 comments

Comments

@scabug
Copy link

scabug commented Nov 29, 2014

For inner classes extending TraversableLike, stringPrefix returns the name of the surrounding object or class.

object Foo {
  class Bar extends IndexedSeq[Any] {
    def length = 0
    def apply(n: Int) = ???
  }
}
new Foo.Bar().stringPrefix // returns "Foo"

The expected output would be "Bar" (which you get if Bar is a member of a package) as stated in the docs of TraversableLike:

bq. By default the string prefix is the simple name of the collection class traversable collection.

"Foo.Bar" or "IndexedSeq" would also be reasonable results, but "Foo" is obviously wrong.

Also of note: If you paste the code into the REPL, the actual result is the empty string (because the code is defined in another surrounding object, I guess).

This issue is not specific to the 2.11.4 release, but is present in previous versions, too.

@scabug
Copy link
Author

scabug commented Nov 29, 2014

Imported From: https://issues.scala-lang.org/browse/SI-9019?orig=1
Reporter: M. Liebermuth (mliebermuth)
Affected Versions: 2.11.4

@scabug
Copy link
Author

scabug commented Dec 6, 2014

@kanielc said:
I can't tell what is the truly desirable behaviour here.
I think according to the specs Foo is the correct expectation, but I do agree it doesn't make sense.

There also seems to be a definite bug in the REPL, as empty string is just illogical here.

@scabug
Copy link
Author

scabug commented Dec 6, 2014

@kanielc said (edited on Dec 6, 2014 4:39:05 AM UTC):
OK, so with some more digging here's what I see.

The stringPrefix returns the first top-level object within the package. That means it gives no meaningful information for nested constructs.
e.g. scala.collection.TraversableLikeTest$Foo$2$Bar => TraversableLikeTest

The REPL uses some interesting naming constructs

scala> b.getClass.getName.toCharArray
res16: Array[Char] = Array($, l, i, n, e, 3, ., $, r, e, a, d, $, $, i, w, $, $, i, w, $, B, a, r)

So due to pinching the text between the last '.' and the first '$' after we end up with "" because we have .$ in the internal representation.

@scabug
Copy link
Author

scabug commented Jan 30, 2015

@Ichoran said:
@kanielc - Do you want to take this one or shall I?

@scabug
Copy link
Author

scabug commented Jan 30, 2015

@kanielc said:
You go ahead, unless you want to tell me the proper behaviour, in which case I can do it.

Your call :)

@scabug
Copy link
Author

scabug commented Jan 30, 2015

@Ichoran said:
I don't know the proper behavior either, but I'm happy to come up with something and take the blame if it's poorly-chosen.

@scabug
Copy link
Author

scabug commented Mar 31, 2015

@Ichoran said:
scala/scala#4421

@scabug
Copy link
Author

scabug commented Jul 5, 2016

@szeiger said:
PR for 2.12.x: scala/scala#5258

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