Skip to content

Explanation backwards on passing lower type to type argument with lower bound #15575

Closed
@s5bug

Description

@s5bug

Compiler version

3.1.3, 3.2.0-RC1

Minimized code

def foo[T >: Any]: Unit = ()
def bar[T]: Unit = foo[T & Any]
def foo[T >: CharSequence]: Unit = ()
foo[String]

Output

-- [E057] Type Mismatch Error: -------------------------------------------------
1 |def bar[T]: Unit = foo[T & Any]
  |                         ^
  |                 Type argument T & Any does not conform to lower bound Any
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | I tried to show that
  |   T & Any
  | conforms to
  |   Any
  | but the comparison trace ended with `false`:
  |
  |   ==> T & Any  <:  Any
  |   <== T & Any  <:  Any = true
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
1 error found
-- [E057] Type Mismatch Error: -------------------------------------------------
1 |foo[String]
  |    ^
  |    Type argument String does not conform to lower bound CharSequence
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | I tried to show that
  |   String
  | conforms to
  |   CharSequence
  | but the comparison trace ended with `false`:
  |
  |   ==> String  <:  CharSequence
  |     ==> String  <:  CharSequence
  |       ==> CharSequence  <:  CharSequence (left is approximated)
  |         ==> (java.lang : java.lang.type)  <:  java.lang.type
  |         <== (java.lang : java.lang.type)  <:  java.lang.type = true
  |       <== CharSequence  <:  CharSequence (left is approximated) = true
  |     <== String  <:  CharSequence = true
  |   <== String  <:  CharSequence = true
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
1 error found

Expectation

  1. An explanation that shows Any <: T & Any = false.
  2. An explanation that shows CharSequence <: String = false.

Metadata

Metadata

Assignees

Labels

area:reportingError reporting including formatting, implicit suggestions, etcitype:bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions