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

Loophole in "no inlined with opaque" checking #12814

Closed
odersky opened this issue Jun 13, 2021 · 0 comments · Fixed by #12815
Closed

Loophole in "no inlined with opaque" checking #12814

odersky opened this issue Jun 13, 2021 · 0 comments · Fixed by #12815
Milestone

Comments

@odersky
Copy link
Contributor

odersky commented Jun 13, 2021

The following code is adapted from a contributors comment

object refined:
  opaque type Positive = Int

  object Positive extends PositiveFactory

  trait PositiveFactory:
    inline def apply(value: Int): Positive = f(value) // error expected here
    def f(x: Positive): Positive = x

@main def run: Unit =
  import refined.*
  val x = 9
  val nine = Positive.apply(x)

Behavior: At phase inlinining, the following error message;

-- [E007] Type Mismatch Error: opaque-inline.scala:14:28 -----------------------
14 |  val nine = Positive.apply(x)
   |                            ^
   |                            Found:    (x : Int)
   |                            Required: refined.Positive

longer explanation available when compiling with `-explain`

The error message makes no sense here. It came from the inlined expansion of f(value) which no longer typechecks
since the code is now outside of the region where the opaque alias was defined.

Expected Either an error on the definition of apply:

-- Error: opaque-inline.scala:8:15 ---------------------------------------------
8 |    inline def apply(value: Int): Positive = f(value)
  |               ^
  |Implementation restriction: No inline methods allowed where opaque type aliases are in scope

Or, if we can lift the implementation restriction, successful compilation with -Ycheck:all passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants