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

Parameterized Java records result in MatchError #18639

Closed
jam01 opened this issue Oct 2, 2023 · 6 comments · Fixed by #19583
Closed

Parameterized Java records result in MatchError #18639

jam01 opened this issue Oct 2, 2023 · 6 comments · Fixed by #19583

Comments

@jam01
Copy link

jam01 commented Oct 2, 2023

Compiler version

An unhandled exception was thrown in the compiler.

 while compiling: <no file>
    during phase: <no phase>
            mode: Mode(ImplicitsEnabled)
 library version: version 2.13.10
compiler version: version 3.3.1
        settings: -bootclasspath ... -d .../target/classes -java-output-version 21

            tree: EmptyTree
   tree position: :<unknown>
       tree type: <notype>
          symbol: val <none>
       call site: package <root> in module class <root>

== Source file context for tree position ==

Minimized code

import java.util.List;

public record Result<U extends Number>(List<U> original,
                                       List<U> removed) { }

Output (click arrow to expand)

-- [E161] Naming Error: Record.java:3:21 ---------------------------------------
3 |public record Result<U extends Number>(List<U> original,
  |                     ^^^^^^^^^^^^^^^^
  |U is already defined as type U
  |
  |Note that overloaded methods must all be defined in the same group of toplevel definitions

scala.MatchError: NoType (of class dotty.tools.dotc.core.Types$NoType$) while typechecking .../Result.java

exception occurred while typechecking .../Result.java

...

scala.MatchError: NoType (of class dotty.tools.dotc.core.Types$NoType$)
dotty.tools.dotc.core.Types$TypeLambdaCompanion.toPInfo(Types.scala:3997)
dotty.tools.dotc.core.Types$TypeLambdaCompanion.toPInfo(Types.scala:3995)
dotty.tools.dotc.core.Types$LambdaTypeCompanion.fromParams$$anonfun$2$$anonfun$1(Types.scala:3983)
scala.collection.immutable.List.map(List.scala:250)
dotty.tools.dotc.core.Types$LambdaTypeCompanion.fromParams$$anonfun$2(Types.scala:3983)
dotty.tools.dotc.core.Types$PolyType.<init>(Types.scala:4197)
dotty.tools.dotc.core.Types$PolyType$.apply(Types.scala:4303)
dotty.tools.dotc.core.Types$PolyType$.apply(Types.scala:4300)
dotty.tools.dotc.core.Types$LambdaTypeCompanion.fromParams(Types.scala:3984)
dotty.tools.dotc.core.NamerOps$.recur$1(NamerOps.scala:54)
dotty.tools.dotc.core.NamerOps$.methodType(NamerOps.scala:56)
dotty.tools.dotc.typer.Namer.wrapMethType$1(Namer.scala:1783)
dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1787)
dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:791)
dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:934)
dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:814)
dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
dotty.tools.dotc.core.NamerOps$ApplyProxyCompleter.complete(NamerOps.scala:106)
dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
dotty.tools.dotc.core.SymDenotations$SymDenotation.annotations(SymDenotations.scala:231)
dotty.tools.dotc.core.SymDenotations$SymDenotation.getAnnotation(SymDenotations.scala:269)
dotty.tools.dotc.core.SymDenotations$SymDenotation.targetName(SymDenotations.scala:573)
dotty.tools.dotc.core.SymDenotations$SymDenotation.hasTargetName(SymDenotations.scala:563)
dotty.tools.dotc.core.Denotations$SingleDenotation.matches(Denotations.scala:1006)
dotty.tools.dotc.typer.Checking.checkDecl$1$$anonfun$2(Checking.scala:1102)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
scala.collection.AbstractIterable.foreach(Iterable.scala:933)
scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:903)
dotty.tools.dotc.typer.Checking.checkDecl$1(Checking.scala:1114)
dotty.tools.dotc.typer.Checking.checkNoDoubleDeclaration$$anonfun$1(Checking.scala:1119)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.immutable.List.foreach(List.scala:333)
dotty.tools.dotc.core.Scopes$Scope.foreach(Scopes.scala:93)
dotty.tools.dotc.typer.Checking.checkNoDoubleDeclaration(Checking.scala:1119)
dotty.tools.dotc.typer.Checking.checkNoDoubleDeclaration$(Checking.scala:809)
dotty.tools.dotc.typer.Typer.checkNoDoubleDeclaration(Typer.scala:116)
dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2671)
dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3081)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
scala.Function0.apply$mcV$sp(Function0.scala:42)
dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.immutable.List.foreach(List.scala:333)
dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
dotty.tools.dotc.Run.compileUnits(Run.scala:279)
dotty.tools.dotc.Run.compileSources(Run.scala:194)
dotty.tools.dotc.Run.compile(Run.scala:179)
dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:179)
sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:177)
sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:463)
sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:418)
sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:405)
sbt.internal.inc.Incremental$.apply(Incremental.scala:171)
sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
sbt_inc.InProcessSbtIncrementalCompiler.compile(InProcessSbtIncrementalCompiler.java:72)
scala_maven.ScalaCompilerSupport.incrementalCompile(ScalaCompilerSupport.java:325)
scala_maven.ScalaCompilerSupport.compile(ScalaCompilerSupport.java:119)
scala_maven.ScalaCompilerSupport.doExecute(ScalaCompilerSupport.java:86)
scala_maven.ScalaMojoSupport.execute(ScalaMojoSupport.java:310)
scala_maven.ScalaCompileMojo.execute(ScalaCompileMojo.java:108)
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
org.apache.maven.cli.MavenCli.execute(MavenCli.java:972)
org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
java.base/java.lang.reflect.Method.invoke(Method.java:580)
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
@jam01 jam01 added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 2, 2023
@jam01
Copy link
Author

jam01 commented Oct 2, 2023

Can be worked around with JavaThenScala order as pointed out in #14846

@bishabosha bishabosha added area:parser area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2023
@bishabosha
Copy link
Member

so the crash is in Namer, but it probably means that the tree produced by the JavaParser was not in the right format

@bishabosha
Copy link
Member

@TheElectronWill it seems you implemented the Records in the parser, maybe you want to try to fix this

@TheElectronWill
Copy link
Contributor

Let me try :)

@bishabosha
Copy link
Member

I have a simpler example

public record B<T>(T obj) {}

@bishabosha
Copy link
Member

I did some work on java parser recently so I can probably handle it

bishabosha added a commit that referenced this issue Feb 9, 2024
This is a dependency of #19577 and should be reviewed and merged first.

fixes #18639
fixes #19386
fixes #19578
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants