Skip to content

Compiler crashes when matching on union in implicit class #2741

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
felixmulder opened this issue Jun 13, 2017 · 2 comments
Closed

Compiler crashes when matching on union in implicit class #2741

felixmulder opened this issue Jun 13, 2017 · 2 comments

Comments

@felixmulder
Copy link
Contributor

felixmulder commented Jun 13, 2017

object Result {
  type ResultF[F] = F | Errors

  case class Errors(msgs: Seq[String])

  implicit class ResultFunctions[A](val res: ResultF[A]) extends AnyVal {
    def map[B](f: A => B): ResultF[B] = res match {
      case errs: Errors => errs
      case x => f(res)
    }
  }
}

Stack trace

[debug] [naha]
[debug] [naha] Initial source changes:
[debug] [naha] 	removed:Set()
[debug] [naha] 	added: Set(/Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Result.scala)
[debug] [naha] 	modified: Set(/Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala)
[debug] [naha] Invalidated products: Set(/Users/fixel/Projects/dotty/repl/../out/bootstrap/dotty-repl/scala-0.2/classes/dotty/tools/repl/Repl$$anon$1.class, /Users/fixel/Projects/dotty/repl/../out/bootstrap/dotty-repl/scala-0.2/classes/dotty/tools/repl/Repl.class)
[debug] [naha] External API changes: API Changes: Set()
[debug] [naha] Modified binary dependencies: Set()
[debug] [naha] Initial directly invalidated sources: Set(/Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala, /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Result.scala)
[debug] [naha]
[debug] [naha] Sources indirectly invalidated by:
[debug] [naha] 	product: Set(/Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala)
[debug] [naha] 	binary dep: Set()
[debug] [naha] 	external source: Set()
[debug] All initially invalidated sources: Set(/Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala, /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Result.scala)
[debug] [naha] Initial set of included nodes: Set(/Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala, /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Result.scala)
[info] Compiling 2 Scala sources to /Users/fixel/Projects/dotty/repl/../out/bootstrap/dotty-repl/scala-0.2/classes...
[debug] Getting ch.epfl.lamp:dotty-sbt-bridge:NOT_PUBLISHED:component from component compiler for Scala 0.2.0-bin-SNAPSHOT-nonbootstrapped
[debug] Getting ch.epfl.lamp:dotty-sbt-bridge:NOT_PUBLISHED:component from component compiler for Scala 0.2.0-bin-SNAPSHOT-nonbootstrapped
[debug] Calling Dotty compiler with arguments  (CompilerInterface):
[debug] 	-feature
[debug] 	-deprecation
[debug] 	-encoding
[debug] 	UTF8
[debug] 	-language:existentials,higherKinds,implicitConversions
[debug] 	-bootclasspath
[debug] 	/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/classes
[debug] 	-Xmax-classfile-name
[debug] 	78
[debug] 	-classpath
[debug] 	/Users/fixel/Projects/dotty/repl/../out/bootstrap/dotty-repl/scala-0.2/classes:/Users/fixel/Projects/dotty/language-server/../out/bootstrap/dotty-language-server/scala-0.2/classes:/Users/fixel/Projects/dotty/compiler/../out/bootstrap/dotty-compiler-bootstrapped/scala-0.2/classes:/Users/fixel/Projects/dotty/interfaces/target/classes:/Users/fixel/Projects/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.2/classes:/Users/fixel/.ivy2/cache/org.scala-lang.modules/scala-asm/bundles/scala-asm-5.1.0-scala-2.jar:/Users/fixel/.ivy2/cache/com.typesafe.sbt/sbt-interface/jars/sbt-interface-0.13.15.jar:/Users/fixel/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.1.jar:/Users/fixel/.ivy2/cache/org.eclipse.lsp4j/org.eclipse.lsp4j/jars/org.eclipse.lsp4j-0.2.0.jar:/Users/fixel/.ivy2/cache/org.eclipse.lsp4j/org.eclipse.lsp4j.generator/jars/org.eclipse.lsp4j.generator-0.2.0.jar:/Users/fixel/.ivy2/cache/org.eclipse.lsp4j/org.eclipse.lsp4j.jsonrpc/jars/org.eclipse.lsp4j.jsonrpc-0.2.0.jar:/Users/fixel/.ivy2/cache/com.google.code.gson/gson/jars/gson-2.7.jar:/Users/fixel/.ivy2/cache/org.eclipse.xtend/org.eclipse.xtend.lib/jars/org.eclipse.xtend.lib-2.12.0.jar:/Users/fixel/.ivy2/cache/org.eclipse.xtext/org.eclipse.xtext.xbase.lib/jars/org.eclipse.xtext.xbase.lib-2.12.0.jar:/Users/fixel/.ivy2/cache/com.google.guava/guava/bundles/guava-18.0.jar:/Users/fixel/.ivy2/cache/org.eclipse.xtend/org.eclipse.xtend.lib.macro/jars/org.eclipse.xtend.lib.macro-2.12.0.jar:/Users/fixel/.ivy2/cache/com.fasterxml.jackson.core/jackson-databind/bundles/jackson-databind-2.8.8.jar:/Users/fixel/.ivy2/cache/com.fasterxml.jackson.core/jackson-annotations/bundles/jackson-annotations-2.8.0.jar:/Users/fixel/.ivy2/cache/com.fasterxml.jackson.core/jackson-core/bundles/jackson-core-2.8.8.jar:/Users/fixel/Projects/dotty/compiler/target/scala-2.11/dotty-compiler_2.11-0.2.0-bin-SNAPSHOT-nonbootstrapped.jar:/Users/fixel/Projects/dotty/interfaces/target/classes:/Users/fixel/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.11.jar:/Users/fixel/.ivy2/cache/org.scala-lang.modules/scala-asm/bundles/scala-asm-5.1.0-scala-2.jar:/Users/fixel/.ivy2/cache/com.typesafe.sbt/sbt-interface/jars/sbt-interface-0.13.15.jar:/Users/fixel/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.1.jar
[info]
[info] exception occurred while typechecking /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Result.scala
[info]
[info] exception occurred while compiling /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Repl.scala, /Users/fixel/Projects/dotty/repl/src/dotty/tools/repl/Result.scala
java.lang.AssertionError: assertion failed
	at scala.Predef$.assert(Predef.scala:156)
	at dotty.tools.dotc.core.Types$OrType.(Types.scala:2337)
	at dotty.tools.dotc.core.Types$CachedOrType.(Types.scala:2364)
	at dotty.tools.dotc.core.Types$OrType$.apply(Types.scala:2369)
	at dotty.tools.dotc.core.Types$OrType$.make(Types.scala:2372)
	at dotty.tools.dotc.core.Types$OrType.derivedOrType(Types.scala:2356)
	at dotty.tools.dotc.core.Types$OrType.derivedAndOrType(Types.scala:2359)
	at dotty.tools.dotc.core.Types$TypeMap.derivedAndOrType(Types.scala:3605)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:3687)
	at dotty.tools.dotc.core.Substituters$class.substParams(Substituters.scala:232)
	at dotty.tools.dotc.core.Contexts$Context.substParams(Contexts.scala:57)
	at dotty.tools.dotc.core.Types$Type.substParams(Types.scala:1275)
	at dotty.tools.dotc.core.Types$LambdaType$class.instantiate(Types.scala:2464)
	at dotty.tools.dotc.core.Types$HKLambda.instantiate(Types.scala:2493)
	at dotty.tools.dotc.core.TypeApplications$$anonfun$appliedTo$extension0$1.tryReduce$1(TypeApplications.scala:404)
	at dotty.tools.dotc.core.TypeApplications$$anonfun$appliedTo$extension0$1.apply(TypeApplications.scala:420)
	at dotty.tools.dotc.core.TypeApplications$$anonfun$appliedTo$extension0$1.apply(TypeApplications.scala:371)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.core.TypeApplications$.appliedTo$extension0(TypeApplications.scala:371)
	at dotty.tools.dotc.core.TypeApplications$.applyIfParameterized$extension(TypeApplications.scala:446)
	at dotty.tools.dotc.core.Types$HKApply.superType(Types.scala:2944)
	at dotty.tools.dotc.core.TypeComparer.compareLower$1(TypeComparer.scala:736)
	at dotty.tools.dotc.core.TypeComparer.compareHkApply2(TypeComparer.scala:748)
	at dotty.tools.dotc.core.TypeComparer.thirdTry(TypeComparer.scala:435)
	at dotty.tools.dotc.core.TypeComparer.secondTry(TypeComparer.scala:352)
	at dotty.tools.dotc.core.TypeComparer.dotty$tools$dotc$core$TypeComparer$$firstTry(TypeComparer.scala:276)
	at dotty.tools.dotc.core.TypeComparer$$anonfun$isSubType$1.apply$mcZ$sp(TypeComparer.scala:117)
	at dotty.tools.dotc.core.TypeComparer$$anonfun$isSubType$1.apply(TypeComparer.scala:109)
	at dotty.tools.dotc.core.TypeComparer$$anonfun$isSubType$1.apply(TypeComparer.scala:109)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:108)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:102)
	at dotty.tools.dotc.core.Types$Type$$anonfun$$less$colon$less$1.apply$mcZ$sp(Types.scala:735)
	at dotty.tools.dotc.core.Types$Type$$anonfun$$less$colon$less$1.apply(Types.scala:735)
	at dotty.tools.dotc.core.Types$Type$$anonfun$$less$colon$less$1.apply(Types.scala:735)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.core.Types$Type.$less$colon$less(Types.scala:734)
	at dotty.tools.dotc.core.Types$Type.relaxed_$less$colon$less(Types.scala:764)
	at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.discardForView$1(Implicits.scala:78)
	at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.discard$1(Implicits.scala:116)
	at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.dotty$tools$dotc$typer$Implicits$ImplicitRefs$$anonfun$$refMatches$1(Implicits.scala:122)
	at dotty.tools.dotc.typer.Implicits$Impli$$$$dc1ba44288197469625d26a59046ea7a$$$$anonfun$apply$1.apply(Implicits.scala:131)
	at dotty.tools.dotc.typer.Implicits$Impli$$$$dc1ba44288197469625d26a59046ea7a$$$$anonfun$apply$1.apply(Implicits.scala:131)
	at scala.collection.TraversableLike$$anonfun$filterImpl$1.apply(TraversableLike.scala:248)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:247)
	at scala.collection.TraversableLike$class.filter(TraversableLike.scala:259)
	at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
	at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.apply(Implicits.scala:131)
	at dotty.tools.dotc.typer.Implicits$ImplicitRefs$$anonfun$filterMatching$1.apply(Implicits.scala:62)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Implicits$ImplicitRefs.filterMatching(Implicits.scala:62)
	at dotty.tools.dotc.typer.Implicits$Conte$$$$56c287cf237b738b2a4f181545d31f9$$$$mputeEligible$2.apply(Implicits.scala:219)
	at dotty.tools.dotc.typer.Implicits$Conte$$$$56c287cf237b738b2a4f181545d31f9$$$$mputeEligible$2.apply(Implicits.scala:217)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Implicits$ContextualImplicits.dotty$tools$dotc$typer$Implicits$ContextualImplicits$$computeEligible(Implicits.scala:217)
	at dotty.tools.dotc.typer.Implicits$ContextualImplicits$$anonfun$eligible$2.apply(Implicits.scala:208)
	at dotty.tools.dotc.typer.Implicits$ContextualImplicits$$anonfun$eligible$2.apply(Implicits.scala:192)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Implicits$ContextualImplicits.eligible(Implicits.scala:191)
	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:884)
	at dotty.tools.dotc.typer.Implicits$$anonfun$inferImplicit$1$$anonfun$apply$24.apply(Implicits.scala:679)
	at dotty.tools.dotc.typer.Implicits$$anonfun$inferImplicit$1$$anonfun$apply$24.apply(Implicits.scala:674)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Implicits$$anonfun$inferImplicit$1.apply(Implicits.scala:674)
	at dotty.tools.dotc.typer.Implicits$$anonfun$inferImplicit$1.apply(Implicits.scala:669)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Implicits$class.inferImplicit(Implicits.scala:669)
	at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:65)
	at dotty.tools.dotc.typer.Implicits$$anonfun$inferView$1.apply(Implicits.scala:527)
	at dotty.tools.dotc.typer.Implicits$$anonfun$inferView$1.apply(Implicits.scala:514)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Implicits$class.inferView(Implicits.scala:513)
	at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:65)
	at dotty.tools.dotc.typer.Typer.adaptToSubType$1(Typer.scala:2077)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2036)
	at dotty.tools.dotc.typer.Typer.adaptInterpolated(Typer.scala:2142)
	at dotty.tools.dotc.typer.Typer$$anonfun$adapt$1$$anonfun$apply$40.apply(Typer.scala:1788)
	at dotty.tools.dotc.typer.Typer$$anonfun$adapt$1$$anonfun$apply$40.apply(Typer.scala:1784)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer$$anonfun$adapt$1.apply(Typer.scala:1784)
	at dotty.tools.dotc.typer.Typer$$anonfun$adapt$1.apply(Typer.scala:1784)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:1783)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:238)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:616)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:614)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:399)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:444)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:238)
	at dotty.tools.dotc.typer.Applications$TypedApply.(Applications.scala:534)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.(Applications.scala:615)
	at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1.dotty$tools$dotc$typer$Applications$class$$anonfun$$simpleApply$1(Applications.scala:671)
	at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1$$anonfun$apply$5.apply(Applications.scala:696)
	at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1$$anonfun$apply$5.apply(Applications.scala:696)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:1700)
	at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1.apply(Applications.scala:697)
	at dotty.tools.dotc.typer.Applications$$anonfun$realApply$1$1.apply(Applications.scala:641)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Applications$class.realApply$1(Applications.scala:641)
	at dotty.tools.dotc.typer.Applications$class.typedApply(Applications.scala:741)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:65)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1577)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1692)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedBlock$1.apply(Typer.scala:624)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedBlock$1.apply(Typer.scala:616)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:616)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1584)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1692)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedCase$1.caseRest$1(Typer.scala:917)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedCase$1.apply(Typer.scala:932)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedCase$1.apply(Typer.scala:886)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:886)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedCases$1.apply(Typer.scala:880)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedCases$1.apply(Typer.scala:880)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:62)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:78)
	at dotty.tools.dotc.typer.Typer.typedCases(Typer.scala:880)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedMatch$1.apply(Typer.scala:852)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedMatch$1.apply(Typer.scala:843)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:842)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1589)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1692)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedDefDef$1.apply(Typer.scala:1262)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedDefDef$1.apply(Typer.scala:1244)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1244)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1565)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1622)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1660)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1680)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1366)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1292)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1292)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1568)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1622)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1660)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1680)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1366)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1292)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1292)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1568)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1622)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1660)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1680)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1483)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1470)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1470)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1607)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1671)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1680)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1483)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1470)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1470)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1607)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1638)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1636)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1636)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1692)
	at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:64)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
	at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:93)
	at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:93)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:87)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:84)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:84)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:72)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:72)
	at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:72)
	at dotty.tools.dotc.Run.compileSources(Run.scala:64)
	at dotty.tools.dotc.Run.compile(Run.scala:48)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
	at dotty.tools.dotc.Driver.process(Driver.scala:124)
	at xsbt.CachedCompilerImpl.run(CompilerInterface.scala:63)
	at xsbt.CachedCompilerImpl.run(CompilerInterface.scala:53)
	at xsbt.CompilerInterface.run(CompilerInterface.scala:37)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:107)
	at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:53)
	at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)
	at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply$mcV$sp(MixedAnalyzingCompiler.scala:50)
	at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50)
	at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50)
	at sbt.compiler.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:74)
	at sbt.compiler.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:49)
	at sbt.compiler.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:64)
	at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
	at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
	at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
	at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
	at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:32)
	at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:72)
	at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:71)
	at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:99)
	at sbt.inc.Incremental$.compile(Incremental.scala:71)
	at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
	at sbt.compiler.IC$.compileInternal(IncrementalCompiler.scala:160)
	at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:138)
	at sbt.Compiler$.compile(Compiler.scala:155)
	at sbt.Compiler$.compile(Compiler.scala:141)
	at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:886)
	at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:877)
	at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:875)
	at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
	at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
	at sbt.std.Transform$$anon$4.work(System.scala:63)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.Execute.work(Execute.scala:237)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
	at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

The following works just fine:

def map[A,B](res: ResultF[A])(f: A => B): ResultF[B] = res match {
  case errs: Errors => errs
  case res: A => f(res)
}
@felixmulder
Copy link
Contributor Author

felixmulder commented Jun 13, 2017

Even more stuff to do with the same bug:

implicit def RichResult[A](res: ResultF[A]): RichResult[A] = new RichResult(res)

sealed class RichResult[A](val res: ResultF[A]) {
  def map[B](f: A => B): ResultF[B] = Result.map[A, B](res)(f)
  def flatMap[B](f: A => ResultF[B]): ResultF[B] = Result.flatMap[A, B](res)(f)
}

private def map[A,B](res: ResultF[A])(f: A => B): ResultF[B] = res match {
  case errs: Errors => errs
  case a: A => f(a)
}

private def flatMap[A,B](res: ResultF[A])(f: A => ResultF[B]): ResultF[B] = res match {
  case errs: Errors => errs
  case a: A => f(a)
}

The above compiles.

This doesn't:

+ private def flatMap[A,B](res: ResultF[A])(f: A => ResultF[B]): ResultF[B] = map[A, B](res)(f)
- private def flatMap[A,B](res: ResultF[A])(f: A => ResultF[B]): ResultF[B] =
-   res match {
-    case errs: Errors => errs
-    case a: A => f(a)
-   }

nor this:

sealed class RichResult[A](val res: ResultF[A]) {
+  def map[B](f: A => B): ResultF[B] = Result.map(res)(f)
-  def map[B](f: A => B): ResultF[B] = Result.map[A, B](res)(f)
  def flatMap[B](f: A => ResultF[B]): ResultF[B] = Result.flatMap[A, B](res)(f)
}

nor this:

sealed class RichResult[A](val res: ResultF[A]) {
  def map[B](f: A => B): ResultF[B] = Result.map[A, B](res)(f)
+  def flatMap[B](f: A => ResultF[B]): ResultF[B] = Result.flatMap(res)(f)
-  def flatMap[B](f: A => ResultF[B]): ResultF[B] = Result.flatMap[A, B](res)(f)
}

@felixmulder
Copy link
Contributor Author

This causes a slew of errors and as such it makes the initially presented pattern unusable :(

felixmulder added a commit that referenced this issue Jun 13, 2017
Fix #2741: Handle wildcard types in unions and intersections.
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

1 participant