Skip to content

Three tweaks #6824

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 4 commits into from
Jul 11, 2019
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: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ object desugar {
*/
private object IdPattern {
def unapply(tree: Tree)(implicit ctx: Context): Option[VarInfo] = tree match {
case id: Ident => Some(id, TypeTree())
case id: Ident if id.name != nme.WILDCARD => Some(id, TypeTree())
case Typed(id: Ident, tpt) => Some((id, tpt))
case _ => None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,15 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
} else tp1
}

/** Read type ref, mapping a TypeRef to a package to the package's ThisType
* Package references should be TermRefs or ThisTypes but it was observed that
* nsc sometimes pickles them as TypeRefs instead.
*/
private def readPrefix()(implicit ctx: Context): Type = readTypeRef() match {
case pre: TypeRef if pre.symbol.is(Package) => pre.symbol.thisType
case pre => pre
}

/** Read a type
*
* @param forceProperType is used to ease the transition to NullaryMethodTypes (commentmarker: NMT_TRANSITION)
Expand All @@ -707,7 +716,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
case THIStpe =>
readSymbolRef().thisType
case SINGLEtpe =>
val pre = readTypeRef()
val pre = readPrefix()
val sym = readDisambiguatedSymbolRef(_.info.isParameterless)
pre.select(sym)
case SUPERtpe =>
Expand All @@ -717,7 +726,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
case CONSTANTtpe =>
ConstantType(readConstantRef())
case TYPEREFtpe =>
var pre = readTypeRef()
var pre = readPrefix()
val sym = readSymbolRef()
pre match {
case thispre: ThisType =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ object Parsers {
}
} else EmptyTree
lhs match {
case (id @ Ident(name: TermName)) :: Nil =>
case (id @ Ident(name: TermName)) :: Nil if name != nme.WILDCARD =>
val vdef = ValDef(name, tpt, rhs)
if (isBackquoted(id)) vdef.pushAttachment(Backquoted, ())
finalizeDef(vdef, mods, start)
Expand Down
11 changes: 2 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1320,15 +1320,8 @@ class Namer { typer: Typer =>
def cookedRhsType = deskolemize(dealiasIfUnit(widenRhs(rhsType)))
def lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.span)
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
if (inherited.exists) {
if (sym.is(Final, butNot = Method)) {
val tp = lhsType
if (tp.isInstanceOf[ConstantType])
tp // keep constant types that fill in for a non-constant (to be revised when inline has landed).
else inherited
}
else inherited
}
if (inherited.exists)
if (isInlineVal) lhsType else inherited
else {
if (sym.is(Implicit))
mdef match {
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/givenFallback.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
trait TC[T] { def x: Int; def y: Int = 0 }

given [T] as TC[T] {
inline val x = 1
}

given as TC[Int] {
inline val x = 2
inline override val y = 3
}

object Test extends App {
val z: 2 = the[TC[Int]].x
val _: 3 = the[TC[Int]].y
}
4 changes: 4 additions & 0 deletions tests/pos/wildcardDefs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test {
val _ = 2
val _ = 3
}