Skip to content

Commit 8a4bcb9

Browse files
Merge pull request #11143 from dotty-staging/fix-#11124
Fix reflect ByName docs and align method names
2 parents d8aab99 + d0433be commit 8a4bcb9

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

compiler/src-bootstrapped/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
16111611
def =:=(that: TypeRepr): Boolean = self =:= that
16121612
def <:<(that: TypeRepr): Boolean = self <:< that
16131613
def widen: TypeRepr = self.widen
1614-
def widenTermRefExpr: TypeRepr = self.widenTermRefExpr
1614+
def widenTermRefByName: TypeRepr = self.widenTermRefExpr
1615+
def widenByName: TypeRepr = self.widenExpr
16151616
def dealias: TypeRepr = self.dealias
16161617
def simplified: TypeRepr = self.simplified
16171618
def classSymbol: Option[Symbol] =

compiler/src/scala/quoted/runtime/impl/Matcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ object Matcher {
209209
case Block(List(DefDef("$anonfun", _, _, _, Some(Apply(Ident(name), _)))), _) => name
210210
case arg => arg.symbol.name
211211
}
212-
val argTypes = args.map(x => x.tpe.widenTermRefExpr)
212+
val argTypes = args.map(x => x.tpe.widenTermRefByName)
213213
val resType = pattern.tpe
214214
val res = Lambda(Symbol.spliceOwner, MethodType(names)(_ => argTypes, _ => resType), (meth, x) => bodyFn(x).changeOwner(meth))
215215
matched(res.asExpr)

library/src-bootstrapped/scala/quoted/Quotes.scala

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,25 +2089,25 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
20892089
def <:<(that: TypeRepr): Boolean
20902090

20912091
/** Widen from singleton type to its underlying non-singleton
2092-
* base type by applying one or more `underlying` dereferences,
2093-
* Also go from => T to T.
2094-
* Identity for all other types. Example:
2095-
*
2096-
* class Outer { class C ; val x: C }
2097-
* def o: Outer
2098-
* <o.x.type>.widen = o.C
2099-
*/
2092+
* base type by applying one or more `underlying` dereferences,
2093+
* Also go from => T to T.
2094+
* Identity for all other types. Example:
2095+
*
2096+
* class Outer { class C ; val x: C }
2097+
* def o: Outer
2098+
* <o.x.type>.widen = o.C
2099+
*/
21002100
def widen: TypeRepr
21012101

21022102
/** Widen from TermRef to its underlying non-termref
2103-
* base type, while also skipping `=>T` types.
2104-
*/
2105-
def widenTermRefExpr: TypeRepr
2103+
* base type, while also skipping ByName types.
2104+
*/
2105+
def widenTermRefByName: TypeRepr
21062106

2107-
/** Follow aliases and dereferences LazyRefs, annotated types and instantiated
2108-
* TypeVars until type is no longer alias type, annotated type, LazyRef,
2109-
* or instantiated type variable.
2110-
*/
2107+
/** Widen from ByName type to its result type. */
2108+
def widenByName: TypeRepr
2109+
2110+
/** Follow aliases, annotated types until type is no longer alias type, annotated type. */
21112111
def dealias: TypeRepr
21122112

21132113
/** A simplified version of this type which is equivalent wrt =:= to this type.
@@ -2439,7 +2439,18 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
24392439
end extension
24402440
end MatchTypeMethods
24412441

2442-
/** Type of a by by name parameter */
2442+
/** Type of a by-name definition of type `=>T`.
2443+
*
2444+
* May represent by-name parameter such as `thunk` in
2445+
* ```scala
2446+
* def log[T](thunk: =>T): T = ...
2447+
* ```
2448+
*
2449+
* May also represent a the return type of a parameterless method definition such as
2450+
* ```scala
2451+
* def foo: Int = ...
2452+
* ```
2453+
*/
24432454
type ByNameType <: TypeRepr
24442455

24452456
/** `TypeTest` that allows testing at runtime in a pattern match if a `TypeRepr` is a `ByNameType` */

library/src-non-bootstrapped/scala/quoted/Quotes.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
13681368
def widen: TypeRepr
13691369

13701370
def widenTermRefExpr: TypeRepr
1371+
def widenTermRefByName: TypeRepr = widenTermRefExpr
13711372

13721373
def dealias: TypeRepr
13731374

tests/run-macros/refined-selectable-macro/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Macro {
1717
private def toTupleImpl(s: Expr[Selectable])(using qctx:Quotes) : Expr[Tuple] = {
1818
import quotes.reflect._
1919

20-
val repr = s.asTerm.tpe.widenTermRefExpr.dealias
20+
val repr = s.asTerm.tpe.widenTermRefByName.dealias
2121

2222
def rec(tpe: TypeRepr): List[(String, TypeRepr)] = {
2323
tpe match {
@@ -51,7 +51,7 @@ object Macro {
5151
private def fromTupleImpl[T: Type](s: Expr[Tuple], newRecord: Expr[Array[(String, Any)] => T])(using qctx:Quotes) : Expr[Any] = {
5252
import quotes.reflect._
5353

54-
val repr = s.asTerm.tpe.widenTermRefExpr.dealias
54+
val repr = s.asTerm.tpe.widenTermRefByName.dealias
5555

5656
def isTupleCons(sym: Symbol): Boolean = sym.owner == defn.ScalaPackageClass && sym.name == "*:"
5757

0 commit comments

Comments
 (0)