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

given declaration picks wrong type #12802

Closed
scf37 opened this issue Jun 12, 2021 · 1 comment · Fixed by #12816
Closed

given declaration picks wrong type #12802

scf37 opened this issue Jun 12, 2021 · 1 comment · Fixed by #12816
Milestone

Comments

@scf37
Copy link

scf37 commented Jun 12, 2021

Compiler version

3.0.0

Minimized code

import scala.quoted._

object Boo:
  def foo(using Quotes): Unit =
    import quotes.reflect._
    given Option[Symbol] = Some[Symbol](???)

Output

Found:    Some[x$1.reflect.Symbol]
Required: Option[Symbol²]

where:    Symbol  is a type in trait reflectModule with bounds <: AnyRef
          Symbol² is a class in package scala

Expectation

Successful compilation since both 'Symbol' should refer to reflect.Symbol and not scala.Symbol

@odersky
Copy link
Contributor

odersky commented Jun 13, 2021

The problem is that resolving quotes.reflect requires an implicit search, which will need to evaluate the given, which will again need to look at the import that's currently being completed. If the import is a wildcard import, it is skipped, which explains the error message. if the import is explicit, as in

  def bar(using Quotes): Unit =
    import quotes.reflect.Symbol
    given Option[Symbol] = Some[Symbol](???)

one gets a Cyclic error message instead:

-- [E046] Cyclic Error: i12802.scala:9:17 --------------------------------------
9 |    given Option[Symbol] = Some[Symbol](???)
  |                 ^
  |                 Cyclic reference involving val <import>

longer explanation available when compiling with `-explain`

soronpo added a commit to soronpo/scala3 that referenced this issue Sep 8, 2022
for this purpose, additional context was required in `TyperState`.
a stack was used for the conversion history.
Also, a more general fix for scala#12802 was applied.
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants