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

scala-reflect: SymbolTable assertion failed when there are multiple overloads with the same name as the type name #11803

Open
neko-kai opened this issue Nov 14, 2019 · 1 comment
Labels
Milestone

Comments

@neko-kai
Copy link

@neko-kai neko-kai commented Nov 14, 2019

The following code:

package object example {
  def Self[A](a: A): Self[A] = ???
  def Self[A](unit: Unit): Self[A] = ???
}

package example {

  trait Self[A] {
    def self: A
  }

  object App extends App {
    println(scala.reflect.runtime.universe.typeOf[Self[Any]].toString)
  }

}

Actual:
Fails with the following exception:

Exception in thread "main" java.lang.AssertionError: assertion failed: Self
	at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:170)
	at scala.reflect.internal.Symbols$Symbol.completeInfo(Symbols.scala:1528)
	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1517)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol$$anon$7.scala$reflect$runtime$SynchronizedSymbols$SynchronizedSymbol$$super$info(SynchronizedSymbols.scala:203)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol.info(SynchronizedSymbols.scala:158)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol.info$(SynchronizedSymbols.scala:158)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol$$anon$7.info(SynchronizedSymbols.scala:203)
	at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1691)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol.getFlag(SynchronizedSymbols.scala:153)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol.getFlag$(SynchronizedSymbols.scala:152)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol$$anon$7.getFlag(SynchronizedSymbols.scala:203)
	at scala.reflect.internal.Symbols$Symbol.hasFlag(Symbols.scala:744)
	at scala.reflect.internal.HasFlags.hasJavaAnnotationFlag(HasFlags.scala:98)
	at scala.reflect.internal.HasFlags.hasJavaAnnotationFlag$(HasFlags.scala:98)
	at scala.reflect.internal.Symbols$Symbol.hasJavaAnnotationFlag(Symbols.scala:221)
	at scala.reflect.internal.Symbols$SymbolContextApiImpl.isJavaAnnotation(Symbols.scala:125)
	at scala.reflect.internal.Symbols$Symbol.symbolKind(Symbols.scala:2646)
	at scala.reflect.internal.Symbols$Symbol.sanitizedKindString(Symbols.scala:2677)
	at scala.reflect.internal.Symbols$Symbol.kindString(Symbols.scala:2685)
	at scala.reflect.internal.Symbols$Symbol.toString(Symbols.scala:2738)
	at scala.reflect.internal.Symbols$ClassSymbol.toString(Symbols.scala:3449)
	at java.base/java.lang.String.valueOf(String.java:3042)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:168)
	at scala.reflect.runtime.SymbolLoaders$PackageScope.$anonfun$enter$1(SymbolLoaders.scala:120)
	at scala.reflect.runtime.SymbolLoaders$PackageScope.enter(SymbolLoaders.scala:120)
	at scala.reflect.runtime.SymbolLoaders.initAndEnterClassAndModule(SymbolLoaders.scala:58)
	at scala.reflect.runtime.SymbolLoaders.initAndEnterClassAndModule$(SymbolLoaders.scala:51)
	at scala.reflect.runtime.JavaUniverse.initAndEnterClassAndModule(JavaUniverse.scala:30)
	at scala.reflect.runtime.SymbolLoaders$PackageScope.$anonfun$lookupEntry$1(SymbolLoaders.scala:151)
	at scala.reflect.runtime.SymbolLoaders$PackageScope.syncLockSynchronized(SymbolLoaders.scala:133)
	at scala.reflect.runtime.SymbolLoaders$PackageScope.lookupEntry(SymbolLoaders.scala:135)
	at scala.reflect.internal.Types$Type.findDecl(Types.scala:989)
	at scala.reflect.internal.Types$Type.decl(Types.scala:591)
	at scala.reflect.internal.SymbolTable.$anonfun$openPackageModule$1(SymbolTable.scala:346)
	at scala.reflect.internal.SymbolTable.$anonfun$openPackageModule$1$adapted(SymbolTable.scala:342)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1274)
	at scala.reflect.internal.SymbolTable.openPackageModule(SymbolTable.scala:342)
	at scala.reflect.internal.SymbolTable.openPackageModule(SymbolTable.scala:397)
	at scala.reflect.runtime.SymbolLoaders$LazyPackageType.$anonfun$complete$5(SymbolLoaders.scala:83)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at scala.reflect.internal.SymbolTable.slowButSafeEnteringPhaseNotLaterThan(SymbolTable.scala:318)
	at scala.reflect.runtime.SymbolLoaders$LazyPackageType.complete(SymbolLoaders.scala:80)
	at scala.reflect.internal.Symbols$Symbol.completeInfo(Symbols.scala:1544)
	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1517)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol$$anon$9.scala$reflect$runtime$SynchronizedSymbols$SynchronizedSymbol$$super$info(SynchronizedSymbols.scala:209)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol.info(SynchronizedSymbols.scala:158)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol.info$(SynchronizedSymbols.scala:158)
	at scala.reflect.runtime.SynchronizedSymbols$SynchronizedSymbol$$anon$9.info(SynchronizedSymbols.scala:209)
	at scala.reflect.internal.Types$TypeRef.baseClasses(Types.scala:2593)
	at scala.reflect.internal.tpe.FindMembers$FindMemberBase.init(FindMembers.scala:37)
	at scala.reflect.internal.tpe.FindMembers$FindMember.init(FindMembers.scala:256)
	at scala.reflect.internal.Types$Type.$anonfun$findMember$1(Types.scala:1033)
	at scala.reflect.internal.Types$Type.findMemberInternal$1(Types.scala:1032)
	at scala.reflect.internal.Types$Type.findMember(Types.scala:1037)
	at scala.reflect.internal.Types$Type.memberBasedOnName(Types.scala:666)
	at scala.reflect.internal.Types$Type.member(Types.scala:630)
	at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:60)
	at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:29)
	at example.App$$typecreator1$1.apply(package.scala:14)
	at scala.reflect.api.TypeTags$WeakTypeTagImpl.tpe$lzycompute(TypeTags.scala:237)
	at scala.reflect.api.TypeTags$WeakTypeTagImpl.tpe(TypeTags.scala:237)
	at scala.reflect.api.TypeTags.typeOf(TypeTags.scala:357)
	at scala.reflect.api.TypeTags.typeOf$(TypeTags.scala:357)
	at scala.reflect.api.Universe.typeOf(Universe.scala:73)
	at example.App$.delayedEndpoint$example$App$1(package.scala:14)
	at example.App$delayedInit$body.apply(package.scala:13)
	at scala.Function0.apply$mcV$sp(Function0.scala:39)
	at scala.Function0.apply$mcV$sp$(Function0.scala:39)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
	at scala.App.$anonfun$main$1(App.scala:73)
	at scala.App.$anonfun$main$1$adapted(App.scala:73)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
	at scala.App.main(App.scala:73)
	at scala.App.main$(App.scala:71)
	at example.App$.main(package.scala:13)
	at example.App.main(package.scala)

Process finished with exit code 1

Note that either removing one of the overloads or moving the Self trait from package example into the package object example makes it work:

// ok
package object example {
  def Self[A](a: A): Self[A] = ???
}
// ok
package object example {
  trait Self[A] {
    def self: A
  }
  def Self[A](a: A): Self[A] = ???
  def Self[A](unit: Unit): Self[A] = ???
}

Motivation for defining methods with the same name is to "package" implicit syntax together with the type in Scala 2, in absence of dotty's import-less extension methods. Example: https://scastie.scala-lang.org/EAdQeqJxTxCdmSlOvBmcag

neko-kai added a commit to 7mind/izumi that referenced this issue Nov 14, 2019
* trifunctorize BIOFork to BIOFork3
* workaround for scala/bug#11803
neko-kai added a commit to 7mind/izumi that referenced this issue Nov 14, 2019
…726)

* Attach BIOFork to F, move catz object out into top-level

* Workaround scala/bug#11803 - move all BIO* classes to package object

* trifunctorize BIOFork to BIOFork3
* workaround for scala/bug#11803
@neko-kai

This comment has been minimized.

Copy link
Author

@neko-kai neko-kai commented Nov 20, 2019

Hmm, this is unlike a typical performance problem or a corner case in scala-reflect, this bug actually means that a class of types is simply unrepresentable in runtime universe currently.

/cc @retronym

@SethTisue SethTisue added this to the Backlog milestone Nov 20, 2019
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.