Skip to content

Cannot compile polymorphic methods with default null value under explicit nulls #24132

@HarrisL2

Description

@HarrisL2

Compiler version

3.7.3-RC2

Minimized code

package issue

def foo[A](s: A = null) = ???

scalac local/implicit.scala -d local/out -classpath "local/out"

import issue.* 

val x = foo[String]()

scalac local/explicit.scala -Yexplicit-nulls -d local/out -classpath "local/out"

Output

-- [E007] Type Mismatch Error: local/explicit.scala:3:8 ------------------------
3 |val x = foo[String]()
  |        ^^^^^^^^^^^
  |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`
1 error found

Expectation

The default argument should not throw an error

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