Skip to content

Can't export all members of mutable.TreeMap (tried with List as well) #9967

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

Closed
mpskowron opened this issue Oct 7, 2020 · 2 comments
Closed

Comments

@mpskowron
Copy link

mpskowron commented Oct 7, 2020

dottyVersion = "0.27.0-RC1"
Please find 3 different verions and 2 different outputs here:

Minimized code

1:

class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]):
  private val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](o)
  
  export sortedMap._

2:

class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]):
  val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](o)
  
  export sortedMap._

3:
notice that all the methods I had to exclude to get rid of error messages from 1 return this.type

class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]):
  private val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](o)
  
  export sortedMap.{mapValuesInPlace => _, toIterable => _, seq => _, --= => _, ++= => _, += => _, addAll => _, subtractAll => _, 
    lazyZip => _, filterInPlace => _, -= => _, addOne => _, subtractOne => _, transform => _, retain => _, _}

Output

1:

[error] 8 |  export sortedMap._
[error]   |                   ^
[error]   |non-private method += in class MaxSizeMap refers to private value sortedMap
[error]   |in its type signature (elem1: (K, V), elem2: (K, V), elems: (K, V)*): 
[error]   |  (MaxSizeMap.this.sortedMap : collection.mutable.TreeMap[K, V])

2 and 3 (same stack trace):
truncated stack trace:

[error] ## Exception when compiling 6 sources to /home/michal/programming/scala/crypto-db/target/scala-0.27/classes
[error] java.lang.AssertionError: assertion failed
[error] dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
[error] dotty.tools.dotc.transform.ResolveSuper.transformDefDef(ResolveSuper.scala:63)
[error] dotty.tools.dotc.transform.MegaPhase.goDefDef(MegaPhase.scala:973)
[error] dotty.tools.dotc.transform.MegaPhase.goDefDef(MegaPhase.scala:974)
[error] dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
[error] dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:426)
[error] dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:436)
[error] dotty.tools.dotc.transform.MegaPhase.recur$3$$anonfun$1(MegaPhase.scala:441)
[error] dotty.tools.dotc.transform.MegaPhase$$Lambda$6255/00000000480AB540.apply(Unknown Source)
[error] scala.collection.immutable.List.mapConserve(List.scala:472)

Expectation

It compiles

@bishabosha
Copy link
Member

bishabosha commented Oct 7, 2020

Thank you for opening this issue.

For 1. It is not clear to me why you should want to export += from sortedMap, What would you expect to happen in this situation?

but the crash in 2 and 3 is troubling

@mpskowron
Copy link
Author

mpskowron commented Oct 7, 2020

Thank you for a quick answer.
For 1. I didn't think about it - you're right, methods like += shouldn't be exported. Anyway, I think it should compile and export all methods that can be exported (maybe with a warning or maybe without). My main motivation to use it in this case is to avoid boilerplate, so exporting anything exportable seems like desired behavior.

smarter added a commit that referenced this issue Oct 11, 2020
Fix #9967: Don't add forwarders for super accessors
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