Skip to content

inline delegate not working with opaque type #6802

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

Closed
japgolly opened this issue Jul 4, 2019 · 9 comments
Closed

inline delegate not working with opaque type #6802

japgolly opened this issue Jul 4, 2019 · 9 comments

Comments

@japgolly
Copy link
Contributor

japgolly commented Jul 4, 2019

minimized code

object X {
  opaque type LineNo = Int
  object LineNo {
    inline def unsafe(i: Int): LineNo = i

    inline delegate hello for LineNo = ${impl}

    private def impl given (r: Reflection): Expr[LineNo] = {
      import r._
      '{unsafe(${rootPosition.startLine})}
    }
  }

  val x1 = the[LineNo] // nope

  import delegate LineNo._
  val x2 = the[LineNo] // nope

  val x3 = LineNo.hello
}

error message

[error] -- Error: X.scala:67:22 
[error] 67 |  val x1 = the[LineNo] // nope
[error]    |                      ^
[error]    |no implicit argument of type X.LineNo was found for parameter x of method the in object DottyPredef
[error] -- Error: X.scala:70:22 
[error] 70 |  val x2 = the[LineNo] // nope
[error]    |                      ^
[error]    |no implicit argument of type X.LineNo was found for parameter x of method the in object DottyPredef.
[error]    |I found:
[error]    |
[error]    |    {
[error]    |      <empty> :X.LineNo
[error]    |    }
[error]    |
[error]    |But method hello in object LineNo does not match type X.LineNo.
[error] two errors found

expectation

  • x1 should work because the implicit is in the companion object
  • x2 should work because we've explicitly imported delegates
@OlivierBlanvillain
Copy link
Contributor

The x1 issue seams to be a duplicate of #6716, but I would expect x2 to compile.

@odersky
Copy link
Contributor

odersky commented Jul 28, 2019

We decided that inline and opaque cannot be mixed. The example now produces this as first error:

4 |    inline def unsafe(i: Int): LineNo = i
  |               ^
  |Implementation restriction: No inline methods allowed where opaque type aliases are in scope
``

@odersky odersky closed this as completed Jul 28, 2019
@benhutchison
Copy link
Contributor

This is a pity as it's likely people, (ie me), will want to combine opaque types and macros, for compile-time checked literal values.

I hit the same issue today, and FWIW this illustrates a reasonable workaround I came to:
https://github.com/benhutchison/compose-scala3-workshop/blob/master/nat/src/main/scala/scala3workshop/nat/Nat.scala#L37

@johnynek
Copy link

Just hit this also. It is a shame these features don't compose.

Is there documentation of which features don't compose? Like a matrix which shows which are prohibited?

@japgolly
Copy link
Contributor Author

@odersky @nicolasstucki How long should we expect the limitation that opaque types and inline can't be combined, to last? Is it something that will be addressed in after 3.0? 3.1? I'm finding that I never use opaque types because of this limitation.

@bblfish
Copy link

bblfish commented Aug 30, 2021

@japgolly did you test the difference to see how much slower things are? I wonder if final would help.

In banana-rdf we have built a framework allowing us to write code independently of the various implementations of RDF, so that we can switch between them with one line of code. Opaque types should help for there to be no leakage of the underlying implementations. But ideally we'd like to also use the relevant function calls from the underlying libraries directly. The lib covers Java, JS and should also come handy with native libs too. There are WASM RDF libs in the works.

@odersky
Copy link
Contributor

odersky commented Aug 30, 2021

Note:opaque and inline can now work together.

@bblfish
Copy link

bblfish commented Aug 30, 2021

Ah latest beta? I'll switch.

@odersky
Copy link
Contributor

odersky commented Aug 30, 2021 via email

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

No branches or pull requests

6 participants