Skip to content

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

@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:

Activity

olhotak

olhotak commented on Apr 3, 2025

@olhotak
Contributor

#22473 is intended to be the eventual fix for this (but it is still work in progress).

added
area:private optionsIssues tied to -Y private/internal compiler settings.
and removed
stat:needs triageEvery issue needs to have an "area" and "itype" label
on Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mrdziuban@olhotak@Gedochao

        Issue actions

          Can't use `-Yexplicit-nulls` along with XML literals · Issue #22914 · scala/scala3