Skip to content

Companion object nested in object missing from implicit scope #6803

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 · 3 comments
Closed

Companion object nested in object missing from implicit scope #6803

japgolly opened this issue Jul 4, 2019 · 3 comments

Comments

@japgolly
Copy link
Contributor

japgolly commented Jul 4, 2019

minimized code

Two files:

In this, the bodies of AsObject and AsPackage are exactly the same.

package blah

import scala.language.implicitConversions
import scala.quoted._
import scala.quoted.autolift._
import scala.tasty._

object AsObject {
  final class LineNo(val lineNo: Int)
  object LineNo {
    def unsafe(i: Int): LineNo = new LineNo(i)
    inline delegate for LineNo = ${impl}
    private def impl given (r: Reflection): Expr[LineNo] = {
      import r._
      '{unsafe(${rootPosition.startLine})}
    }
  }
}

package AsPackage {
  final class LineNo(val lineNo: Int)
  object LineNo {
    def unsafe(i: Int): LineNo = new LineNo(i)
    inline delegate for LineNo = ${impl}
    private def impl given (r: Reflection): Expr[LineNo] = {
      import r._
      '{unsafe(${rootPosition.startLine})}
    }
  }
}
import blah._

def testO(): Unit = {
  import AsObject.LineNo
  the[LineNo]
}

def testP(): Unit = {
  import AsPackage.LineNo
  the[LineNo]
}

error message

[error] -- Error: X2.scala:5:13 
[error] 5 |  the[LineNo]
[error]   |             ^
[error]   |no implicit argument of type blah.AsObject.LineNo was found for parameter x of method the in object DottyPredef.
[error]   |I found:
[error]   |
[error]   |    {
[error]   |      <empty> :blah.AsObject.LineNo
[error]   |    }
[error]   |
[error]   |But method LineNo_instance in object LineNo does not match type blah.AsObject.LineNo.
[error] one error found

expectation

There shouldn't be any compilation errors. Putting LineNo in an object should be the same as putting it in a package.

@odersky
Copy link
Contributor

odersky commented Jul 4, 2019

I verified that the macro call is essential to make it fail. If you replace ${impl} by ??? both versions compile.

@nicolasstucki
Copy link
Contributor

It seems that marking the delegate as a macro changes its visibility

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jul 4, 2019

I also noticed that passing the delegate explicitly hits another bug. This other issue was fixed in #6809.

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

3 participants