Skip to content

Very obscure error message when cause is unboxing of parameter bounds #24543

@odersky

Description

@odersky

Compiler version

3.8.0-RC2

Minimized example

import scala.language.experimental.captureChecking

def hh[T <: Ref^](x: Box[T]): Unit =
  val y: (Ref^, Int) = (x.elem, 1)

Output

4 |  val y: (Ref^, Int) = (x.elem, 1)
  |                       ^^^^^^^^^^^
  |    Found:    (T^'s1, Int)
  |    Required: (Ref^, Int)
  |
  |    Note that capability cap is not included in capture set {}.
  |
  |    where:    ^   refers to a fresh root capability in the type of value y
  |              cap is a fresh root capability in the type of type T
  |
  | longer explanation available when compiling with `-explain`

Expectation

Either no error, or a clearer error message that shows the cause of the problem. If I compile with -explain -Ycc-verbose I see

4 |  val y: (Ref^, Int) = (x.elem, 1)
  |                       ^^^^^^^^^^^
  |          Found:    (box T^'s1, Int)
  |          Required: (box Ref^{cap}, Int)
  |
  |          Note that capability cap² is not included in capture set {}.
  |
  |          where:    cap  is a fresh root capability in the type of value y
  |                    cap² is a fresh root capability in the type of type T
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree:
  |
  | Tuple2.apply[T, Int](x.elem, 1)
  |
  | I tried to show that
  |   (box T^'s1, Int)
  | conforms to
  |   (box Ref^{<fresh in value y hiding 's2>}, Int)
  | but none of the attempts shown below succeeded:
  |
  |   ==> (box T^'s1, Int)  <:  (box Ref^{<fresh in value y hiding 's2>}, Int)
  |     ==> box T^'s1  <:  box Ref^{<fresh in value y hiding 's2>}
  |       ==> T  <:  Ref^{<fresh in value y hiding 's2>}
  |         ==> T  <:  Ref
  |           ==> box Ref^{<fresh in method hh hiding 's3>}  <:  Ref
  |             ==> subcaptures {<fresh in method hh hiding 's3>} <:< {} in open varState
  |               ==> {} accountsFor <fresh in method hh hiding 's3> with {<fresh in method hh hiding 's3>}  = false
  |         ==> box Ref^{<fresh in method hh hiding 's3>}  <:  Ref^{<fresh in value y hiding 's2>}
  |           ==> {} accountsFor <fresh in method hh hiding 's3> with {<fresh in method hh hiding 's3>}  = false
  |           ==> {} accountsFor <fresh in method hh hiding 's3> with {<fresh in method hh hiding 's3>}  = false
  |     ==> (box T^'s1, Int)  <:  (box Ref^{<fresh in value y hiding '{<fresh in method hh hiding 's3>}>}, Int)
  |       ==> box T^'s1  <:  box Ref^{<fresh in value y hiding '{<fresh in method hh hiding 's3>}>}
  |         ==> T  <:  Ref^{<fresh in value y hiding '{<fresh in method hh hiding 's3>}>}
  |           ==> T  <:  Ref
  |             ==> box Ref^{<fresh in method hh hiding 's3>}  <:  Ref
  |               ==> subcaptures {<fresh in method hh hiding 's3>} <:< {} in open varState
  |                 ==> {} accountsFor <fresh in method hh hiding 's3> with {<fresh in method hh hiding 's3>}  = false
  |           ==> box Ref^{<fresh in method hh hiding 's3>}  <:  Ref^{<fresh in value y hiding '{<fresh in method hh hiding 's3>}>}
  |             ==> {} accountsFor <fresh in method hh hiding 's3> with {<fresh in method hh hiding 's3>}  = false
  |             ==> {} accountsFor <fresh in method hh hiding 's3> with {<fresh in method hh hiding 's3>}  = false
  |
  | The tests were made under the empty constraint

The critical part are in the last three lines: We are comparing a box Ref^ with a Ref^, that's why it fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:experimental:ccCapture checking relatedarea:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions