Skip to content

Can't use -Yexplicit-nulls along with XML literals #22914

Open
@mrdziuban

Description

@mrdziuban

Compiler version

3.3.5, 3.4.3, 3.5.2, 3.6.4, and latest nightly 3.7.1-RC1-bin-20250402-a8cf11d-NIGHTLY

Minimized code

Running scala-cli like this:

scala-cli -Yexplicit-nulls -S 3.6.4 --dep org.scala-lang.modules::scala-xml:2.3.0

and then evaluating this code:

<test />

Output

-- [E007] Type Mismatch Error: -------------------------------------------------
1 |<test />
  | ^
  |Found:    Null
  |Required: String
  |Note that implicit conversions were not tried because the result of an implicit conversion
  |must be more specific than String
  |
  | longer explanation available when compiling with `-explain`

Expectation

I could use these two features together.

Running with -Xprint:typer I can see why the error happens:

[[syntax trees at end of                     typer]] // rs$line$1
package <empty> {
  final lazy module val rs$line$1: rs$line$1 = new rs$line$1()
  final module class rs$line$1() extends Object() { this: rs$line$1.type =>
    val res0: <error unspecified error> =
      {
        new _root_.scala.xml.Elem(null, "test", _root_.scala.xml.Null,
                               // ^^^^ null passed here
          scala.xml.TopScope, true, [ : scala.xml.Node]*)
      }
  }
}

There's probably more to it, but at first glance it looks like a binary compatible fix would require two changes:

  1. Updating scala-xml to allow an empty string as a prefix: scala/scala-xml@main...mrdziuban:allow-empty-prefix
  2. Updating XML literals to use an empty string instead of null for the prefix here:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions