Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
s5bug opened this issue Jul 4, 2022 · 1 comment · Fixed by #15577
Closed

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

s5bug opened this issue Jul 4, 2022 · 1 comment · Fixed by #15577
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Milestone

Comments

@s5bug
Copy link

s5bug commented Jul 4, 2022

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.
@s5bug s5bug added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 4, 2022
@s5bug
Copy link
Author

s5bug commented Jul 4, 2022

Oh, this is true of type arguments for traits too:

scala> trait Bar[A, B >: A]
// defined trait Bar

scala> type Qux = Bar[CharSequence, String]
-- [E057] Type Mismatch Error: -------------------------------------------------
1 |type Qux = Bar[CharSequence, 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

which makes me think that this could be the root cause of #15568, as that's a very similar issue?

odersky added a commit to dotty-staging/dotty that referenced this issue Jul 4, 2022
@prolativ prolativ added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 4, 2022
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants