question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False type mismatch involving the singleton type of the result of a transparent inline method

See original GitHub issue

Compiler version

3.1.2

Minimized code

trait Quotes

transparent inline def quotes(using q: Quotes) = q

class QuotesExt[Q <: Quotes]

object QuotesExt {
  def apply(q: Quotes): QuotesExt[q.type] =
    new QuotesExt[q.type]
}

def foo(q: Quotes, qe: QuotesExt[q.type]): Unit =
  ()

def doesNotCompile(using Quotes): Unit =
  foo(quotes, QuotesExt(quotes))

// Workaround 1: use explicit type annotation
def compiles(using Quotes): Unit =
  foo(quotes: quotes.type, QuotesExt(quotes))

// Workaround 2: avoid the transparent inline method `quotes`
def alsoCompiles(using q: Quotes): Unit =
  foo(q, QuotesExt(q))

Output

-- [E007] Type Mismatch Error: test.scala:16:23 --------------------------------
16 |  foo(quotes, QuotesExt(quotes))
   |              ^^^^^^^^^^^^^^^^^
   |      Found:    QuotesExt[(x$1 : Quotes)]
   |      Required: QuotesExt[(?1 : (using q: Quotes): Quotes)]
   |
   |      where:    ?1 is an unknown value of type (using q: Quotes): Quotes

longer explanation available when compiling with `-explain`
1 error found

Expectation

The code should compile.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolasstuckicommented, May 4, 2022

Workaround

- def foo(q: Quotes, qe: QuotesExt[q.type]): Unit =
+ def foo(q: Quotes)(qe: QuotesExt[q.type]): Unit =
1reaction
mbovelcommented, May 4, 2022

Note: if foo is curried, then the snippet compiles successfully:

object Foo
transparent inline def id(x: Object) = x
def sameType(x: Object)(y: x.type) = true
val x = sameType(id(Foo))(Foo)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline - Scala 3 - EPFL
Here, the inline method choose returns an instance of either of the two types A or B . If choose had not been...
Read more >
Strange type mismatch with a macro: found - Stack Overflow
1 Answer 1 ... You're making your life harder by trying to funnel your type information back through the names of type parameters...
Read more >
Inline
The inline method is a "blackbox" in the sense that details of its implementation do not leak out. But if a transparent modifier...
Read more >
Node.js v19.3.0 Documentation
When assert.doesNotThrow() is called, it will immediately call the fn function. If an error is thrown and it is the same type as...
Read more >
VBA Type Mismatch Error - The Ultimate Guide
In general, VBA is very forgiving when you assign the wrong value type to a variable e.g.. Dim x As Long ' VBA...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found