Skip to content

Fix #239 - handling of package objects #282

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

Merged
merged 2 commits into from
Dec 16, 2014

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 13, 2014

References to .package are now also inserted if the
accessed member comes from a class inherited by a package
object.

Closes #239

Review by @retronym

@odersky
Copy link
Contributor Author

odersky commented Dec 13, 2014

Note that -Ycheck caught the problem with the included test file before the fix was made.

References to `.package` are now also inserted if the
accessed member comes from a class inherited by a package
object.
@odersky odersky force-pushed the fix/i0239-package-objects branch from 58e370b to 9bc3bb2 Compare December 13, 2014 17:03
@@ -124,7 +124,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
normalizeType {
val qual = tree.qualifier
qual.symbol.moduleClass.denot match {
case pkg: PackageClassDenotation if tree.symbol.maybeOwner.isPackageObject =>
case pkg: PackageClassDenotation if !tree.symbol.maybeOwner.is(Package) =>
cpy.Select(tree)(qual select pkg.packageObj.symbol, tree.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this assign a position to Select(qual, TermName("package"))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Mon, Dec 15, 2014 at 12:43 AM, Jason Zaugg [email protected]
wrote:

In src/dotty/tools/dotc/transform/FirstTransform.scala
#282 (diff):

@@ -124,7 +124,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
normalizeType {
val qual = tree.qualifier
qual.symbol.moduleClass.denot match {

  •    case pkg: PackageClassDenotation if tree.symbol.maybeOwner.isPackageObject =>
    
  •    case pkg: PackageClassDenotation if !tree.symbol.maybeOwner.is(Package) =>
       cpy.Select(tree)(qual select pkg.packageObj.symbol, tree.name)
    

Does this assign a position to Select(qual, TermName("package"))?

Yes, it's the position of qual.

  • Martin


Reply to this email directly or view it on GitHub
https://github.com/lampepfl/dotty/pull/282/files#r21800912.

Martin Odersky
EPFL

@retronym
Copy link
Member

There are some gaps with inherited implicit members:

package p {
  class C[A] { implicit def foo: M[A] = ??? }

  object `package` extends C[String]

  object test0 {
    def compute[A](implicit m: M[A]): A = ???
    val v = compute
    val v1: String = v
  }
}

trait M[A]

object test1 {

  def compute[A](implicit m: M[A]): A = ???

  import p._
  val v = compute
  val v1: String = v
}


I tested this with dotty (as at this PR) and scalac.

Dotty fails with:

./bin/dotc sandbox/test.scala
sandbox/test.scala:8: error: type mismatch:
 found   : => M[String](p.foo)
 required: M[(A? = p$C$$A)]
    val v = compute
                   ^
sandbox/test.scala:9: error: type mismatch:
 found   : p$C$$A(p.test0.v)
 required: String
    val v1: String = v
                     ^
sandbox/test.scala:20: error: type mismatch:
 found   : => M[String](p.foo)
 required: M[(A? = p$C$$A)]
  val v = compute
                 ^
sandbox/test.scala:21: error: type mismatch:
 found   : p$C$$A(test1.v)
 required: String
  val v1: String = v
                   ^
four errors found

Scalac compiles successfully.

Like TypeAssigner, asSeenFrom needs to insert a package object if the
prefix is a package but the class enclosing the type is not.
@odersky
Copy link
Contributor Author

odersky commented Dec 15, 2014

Good catch. I added a patch that fixes this.

@retronym
Copy link
Member

LGTM. Patching ASF seems to address the problem in a more centralized way than we managed in scalac.

You might like to try a few more test cases from scala/scala#4001. Sorry that I forgot to point out this one yesterday.

Perhaps the most esoteric one was related to insertion of an apply call for pack.O(), where O is defined in the package object.

odersky added a commit that referenced this pull request Dec 16, 2014
@odersky odersky merged commit 63e1bc9 into scala:master Dec 16, 2014
retronym added a commit to retronym/scala that referenced this pull request Jan 16, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
tranaparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

It also lets us remove the fix for SI-6225.

[1] scala/scala3#282
retronym added a commit to retronym/scala that referenced this pull request Jan 16, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
tranaparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

It also lets us remove the fix for SI-6225.

[1] scala/scala3#282
retronym added a commit to retronym/scala that referenced this pull request Jan 16, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
transparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

This subsumes the former fix for SI-6225, which is removed here.

[1] scala/scala3#282
retronym added a commit to retronym/scala that referenced this pull request Jan 16, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
transparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

This subsumes the former fix for SI-6225, which is removed here.

[1] scala/scala3#282
retronym added a commit to retronym/scala that referenced this pull request Jan 20, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
transparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

This subsumes the former fix for SI-6225, which is removed here.

[1] scala/scala3#282
retronym added a commit to retronym/scala that referenced this pull request Mar 24, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
transparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

This subsumes the former fix for SI-6225, which is removed here.

[1] scala/scala3#282
retronym added a commit to retronym/scala that referenced this pull request Mar 24, 2015
Takes a leaf out of dotty's book [1] and makes `asSeenFrom`
transparently change the prefix from the package class to the
package object when needed.

This fixes generic subsitution during overload resolution, as
reported in SI-9074.

This subsumes the former fix for SI-6225, which is removed here.

[1] scala/scala3#282
tgodzik added a commit to tgodzik/scala3 that referenced this pull request Apr 29, 2025
Backport "Make sure Block does not incorrectly match a TypeBlock" to 3.3 LTS
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 this pull request may close these issues.

Review treatment of inherited package object members
2 participants