Skip to content

Inference failure with unconstrained type parameter #20235

Open
@lrytz

Description

@lrytz

Using 3.4.1

class C:
  class I
  def m(i: I) = 0

class D:
  def f[T]: C { type FT = T } = ???
  def t = f.m(null)
  // def u = f[Nothing].m(null) // works
➜ sandbox sc3 C.scala -O -explain
> scala compile --server=false -S 3 -d . -release 8 C.scala -O -explain
-- [E007] Type Mismatch Error: /Users/luc/code/scala/scala13/sandbox/C.scala:7:14
7 |  def t = f.m(null)
  |              ^^^^
  |Found:    Null
  |Required: Nothing
  |Note that implicit conversions were not tried because the result of an implicit conversion
  |must be more specific than Nothing
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: null
  | I tried to show that
  |   Null
  | conforms to
  |   Nothing
  | but none of the attempts shown below succeeded:
  |
  |   ==> Null  <:  Nothing  = false
  |
  | The tests were made under a constraint with:
  |  uninstantiated variables: T
  |  constrained types: [T]: C{type FT = T}
  |  bounds:
  |      T
  |  ordering:
  |  co-deps:
  |  contra-deps:
   -----------------------------------------------------------------------------
1 error found
Compilation failed

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