Skip to content

Exception throw when compiling a project: java.lang.NullPointerException: tried to cast away nullability, but value is null #15845

Closed
@OndrejSpanel

Description

@OndrejSpanel

Compiler version

3.1.3

Minimized example

I am afraid I do not have a minimized example yet, I will need some advice on how to extract it.

I am trying to port my complex project to Scala 3. I have fixed most deprecation warnings in 2.13 and upgraded almost all libraries. I am not getting much compiler errors any more, but still use both "-source:3.0-migration" and "-Xignore-scala2-macros", as not all libraries are ported and I still need to compile the project as 2.13 one.

Output

When building my project with Scala 3.1.3, I get following error:

Exception when compiling 382 sources to .......
java.lang.NullPointerException: tried to cast away nullability, but value is null

I am not told which part of the project / what particulat Scala source is the compiler working at, therefore I have no idea how could I pinpoint the problem.

The top of the callstack is:

[error] java.lang.NullPointerException: tried to cast away nullability, but value is null
[error] scala.runtime.Scala3RunTime$.nn(Scala3RunTime.scala:19)
[error] dotty.tools.dotc.core.OrderingConstraint.swapKey$1(OrderingConstraint.scala:495)
[error] dotty.tools.dotc.core.OrderingConstraint.subst(OrderingConstraint.scala:496)
[error] dotty.tools.dotc.core.OrderingConstraint.subst(OrderingConstraint.scala:494)
[error] dotty.tools.dotc.core.TyperState.ensureNotConflicting$$anonfun$1(TyperState.scala:181)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.core.TyperState.ensureNotConflicting(TyperState.scala:182)
[error] dotty.tools.dotc.core.TyperState.mergeConstraintWith(TyperState.scala:193)
[error] dotty.tools.dotc.core.TyperState.commit(TyperState.scala:163)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3111)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1002)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1040)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:327)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:117)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2832)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3080)
[error] dotty.tools.dotc.typer.Typer.$anonfun$47(Typer.scala:2278)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:248)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2278)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2808)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2476)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2820)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2824)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2476)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2820)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2824)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2603)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2865)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3013)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2603)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2865)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3080)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:43)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
[error] scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:414)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:50)
[error] dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:84)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:84)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:225)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:236)```

Expectation

I think compiler can show errors, but should never throw exceptions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions