Skip to content

Commit

Permalink
unthis
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Nov 15, 2022
1 parent 7aef3f7 commit 2762119
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/quasiquotes/Parsers.scala
Expand Up @@ -92,7 +92,7 @@ trait Parsers { self: Quasiquotes =>
case _ => gen.mkBlock(stats, doFlatten = true)
}
case nme.unapply => gen.mkBlock(stats, doFlatten = false)
case other => this.global.abort("unreachable")
case other => global.abort("unreachable")
}

// tq"$a => $b"
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Expand Up @@ -2098,7 +2098,7 @@ self =>
if (in.token == SUBTYPE || in.token == SUPERTYPE) wildcardType(start, scala3Wildcard)
else atPos(start) { Bind(tpnme.WILDCARD, EmptyTree) }
} else {
this.typ() match {
typ() match {
case Ident(name: TypeName) if nme.isVariableName(name) =>
atPos(start) { Bind(name, EmptyTree) }
case t => t
Expand Down Expand Up @@ -2289,7 +2289,7 @@ self =>
}
/** The implementation of the context sensitive methods for parsing outside of patterns. */
final val outPattern = new PatternContextSensitive {
def argType(): Tree = this.typ()
def argType(): Tree = typ()
def functionArgType(): Tree = paramType(repeatedParameterOK = false, useStartAsPosition = true)
}
/** The implementation for parsing inside of patterns at points where sequences are allowed. */
Expand Down
Expand Up @@ -386,7 +386,7 @@ trait MacroAnnotationNamers { self: Analyzer =>
sym.setInfo(new MaybeExpandeeCompleter(tree) {
override def kind = s"maybeExpandeeCompleter for ${sym.accurateKindString} ${sym.rawname}#${sym.id}"
override def maybeExpand(): Unit = {
val companion = if (this.tree.isInstanceOf[ClassDef]) patchedCompanionSymbolOf(sym, context) else NoSymbol
val companion = if (tree.isInstanceOf[ClassDef]) patchedCompanionSymbolOf(sym, context) else NoSymbol

def maybeExpand(annotation: Tree, annottee: Tree, maybeExpandee: Tree): Option[List[Tree]] =
if (context.macrosEnabled) { // TODO: when is this bit flipped -- can we pull this check out farther?
Expand All @@ -395,7 +395,7 @@ trait MacroAnnotationNamers { self: Analyzer =>
if (mann.isClass && mann.hasFlag(MACRO)) {
assert(!currentRun.compiles(mann), mann)
val annm = prepareAnnotationMacro(annotation, mann, sym, annottee, maybeExpandee)
expandAnnotationMacro(this.tree, annm)
expandAnnotationMacro(tree, annm)
// if we encounter an error, we just return None, so that other macro annotations can proceed
// this is unlike macroExpand1 when any error in an expandee blocks expansions
// there it's necessary in order not to exacerbate typer errors
Expand Down Expand Up @@ -424,7 +424,7 @@ trait MacroAnnotationNamers { self: Analyzer =>
enterSyms(expanded) // TODO: we can't reliably expand into imports, because they won't be accounted by definitions below us
case None =>
markNotExpandable(sym)
finishSymbolNotExpandee(this.tree)
finishSymbolNotExpandee(tree)
}

// take care of the companion if it's no longer needed
Expand Down
4 changes: 2 additions & 2 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -772,8 +772,8 @@ trait Types
def withFilter(p: Type => Boolean) = new FilterMapForeach(p)

class FilterMapForeach(p: Type => Boolean) extends FilterTypeCollector(p){
def foreach[U](f: Type => U): Unit = this.collect(Type.this).foreach(f)
def map[T](f: Type => T): List[T] = this.collect(Type.this).map(f)
def foreach[U](f: Type => U): Unit = collect(Type.this) foreach f
def map[T](f: Type => T): List[T] = collect(Type.this) map f
}

@inline final def orElse(alt: => Type): Type = if (this ne NoType) this else alt
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/io/ZipArchive.scala
Expand Up @@ -392,7 +392,7 @@ final class ManifestResources(val url: URL) extends ZipArchive(null) {
if (!zipEntry.isDirectory) {
class FileEntry() extends Entry(zipEntry.getName) {
override def lastModified = zipEntry.getTime()
override def input = resourceInputStream(this.path)
override def input = resourceInputStream(path)
override def sizeOption = None
}
val f = new FileEntry()
Expand Down
2 changes: 1 addition & 1 deletion src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
Expand Up @@ -927,7 +927,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
else None
def resultType =
makeTypeInTemplateContext(aSym.tpe, this.inTpl, aSym)
makeTypeInTemplateContext(aSym.tpe, inTpl, aSym)
def isImplicit = aSym.isImplicit
}

Expand Down
15 changes: 15 additions & 0 deletions test/files/neg/t11921-alias.check
@@ -0,0 +1,15 @@
t11921-alias.scala:16: error: reference to TT is ambiguous;
it is both defined in object O and available as type TT in class C
Since 2.13.11, symbols inherited from a superclass no longer shadow symbols defined in an outer scope.
If shadowing was intended, write `this.TT`.
Or use `-Ylegacy-binding` to enable the previous behavior everywhere.
def n(x: TT) = x // ambiguous
^
t11921-alias.scala:36: error: reference to c is ambiguous;
it is both defined in class B and available as value c in class A
Since 2.13.11, symbols inherited from a superclass no longer shadow symbols defined in an outer scope.
If shadowing was intended, write `this.c`.
Or use `-Ylegacy-binding` to enable the previous behavior everywhere.
def n = c // ambiguous
^
2 errors
39 changes: 39 additions & 0 deletions test/files/neg/t11921-alias.scala
@@ -0,0 +1,39 @@
object t1 {
class C[T] { type TT = T }
object O {
type TT = String
class D extends C[TT] {
def n(x: TT) = x // OK
}
}
}

object t2 {
class C[T] { type TT <: T }
object O {
type TT = String
class D extends C[TT] {
def n(x: TT) = x // ambiguous
}
}
}

object t3 {
trait Context
class A[C <: Context](val c: C)
class B(val c: Context) { b =>
val a = new A[c.type](c) {
def n = c // OK
}
}
}

object t4 {
trait Context
class A[C <: Context](val c: C)
class B(val c: Context) { b =>
val a = new A(c) {
def n = c // ambiguous
}
}
}
2 changes: 1 addition & 1 deletion test/files/run/macroPlugins-macroExpand/Plugin_1.scala
Expand Up @@ -18,7 +18,7 @@ class Plugin(val global: Global) extends NscPlugin {
object expander extends DefMacroExpander(typer, expandee, mode, pt) {
override def onSuccess(expanded: Tree) = {
val message = s"expanded into ${expanded.toString}"
this.typer.typed(q"println($message)")
typer.typed(q"println($message)")
}
}
Some(expander(expandee))
Expand Down

0 comments on commit 2762119

Please sign in to comment.