Skip to content

Commit

Permalink
Add isMethodWithByNameArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Sep 7, 2023
1 parent 95b6ed8 commit c1c2f3f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ class Definitions {
case info: MethodType =>
!info.resType.isInstanceOf[MethodOrPoly] && // Has only one parameter list
!info.isVarArgsMethod &&
!info.paramInfos.exists(_.isInstanceOf[ExprType]) // No by-name parameters
!info.isMethodWithByNameArgs // No by-name parameters
case _ => false
info match
case info: PolyType => isValidMethodType(info.resType)
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ object Types {
case _ => false
}

/** Is this the type of a method that has a by-name parameters? */
def isMethodWithByNameArgs(using Context): Boolean = stripPoly match {
case mt: MethodType => mt.paramInfos.exists(_.isInstanceOf[ExprType])
case _ => false
}

/** Is this the type of a method with a leading empty parameter list?
*/
def isNullaryMethod(using Context): Boolean = stripPoly match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Recheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ abstract class Recheck extends Phase, SymTransformer:
* of `mapExprType`.
*/
def normalizeByName(mbr: SingleDenotation)(using Context): SingleDenotation = mbr.info match
case mt: MethodType if mt.paramInfos.exists(_.isInstanceOf[ExprType]) =>
case mt: MethodType if mt.isMethodWithByNameArgs =>
mbr.derivedSingleDenotation(mbr.symbol,
mt.derivedLambdaType(paramInfos = mt.paramInfos.map(_.mapExprType)))
case _ =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ object Nullables:
def postProcessByNameArgs(fn: TermRef, app: Tree)(using Context): Tree =
fn.widen match
case mt: MethodType
if mt.paramInfos.exists(_.isInstanceOf[ExprType]) && !fn.symbol.is(Inline) =>
if mt.isMethodWithByNameArgs && !fn.symbol.is(Inline) =>
app match
case Apply(fn, args) =>
object dropNotNull extends TreeMap:
Expand Down

0 comments on commit c1c2f3f

Please sign in to comment.