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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ trait TypeOps { this: Context =>
case SuperType(thispre, _) => thispre
case _ => pre
}
else if ((pre.termSymbol is Package) && !(thiscls is Package))
toPrefix(pre.select(nme.PACKAGE), cls, thiscls)
else
toPrefix(pre.baseTypeRef(cls).normalizedPrefix, cls.owner, thiscls)
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/FirstTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

case _ =>
tree
Expand Down
16 changes: 8 additions & 8 deletions src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ trait TypeAssigner {
def ensureAccessible(tpe: Type, superAccess: Boolean, pos: Position)(implicit ctx: Context): Type = {

def tryInsertPackageObj(tpe: NamedType, d: Denotation): Type = {
def tryInsert: Type =
if (!(d.symbol.maybeOwner is Package)) {
val symOwner = d.alternatives.head.symbol.owner
if (symOwner.isPackageObject) tpe.derivedSelect(symOwner.thisType)
else tpe
} else tpe
def tryInsert(pkgClass: SymDenotation): Type = pkgClass match {
case pkgCls: PackageClassDenotation if !(d.symbol.maybeOwner is Package) =>
tpe.derivedSelect(pkgCls.packageObj.valRef)
case _ =>
tpe
}
tpe.prefix match {
case pre: ThisType if pre.cls is Package => tryInsert
case pre: TermRef if pre.symbol is Package => tryInsert
case pre: ThisType if pre.cls is Package => tryInsert(pre.cls)
case pre: TermRef if pre.symbol is Package => tryInsert(pre.symbol.moduleClass)
case _ => tpe
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/pos/i0239.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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
}
11 changes: 11 additions & 0 deletions tests/pos/i239-packageObj.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package p {
class C[A] { def foo: A = ??? }

object `package` extends C[String]
}

object test {

val x: String = p.foo

}