Skip to content

Commit a2b3bc1

Browse files
committed
Don't set PureInterface when a default param is present
The default param will be desugared into a method with a body, so setting PureInterface would be wrong. The enclosed test previously failed with a pickling difference, because the unpickler correctly decided to not set the PureInterface flag since it saw the default param method. This fixes the tasty_dotc_util which failed since the last commit because FreshNameCreator was now incorrectly recognized as a PureInterface.
1 parent 279dd3b commit a2b3bc1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
3131
* Does tree contain an initialization part when seen as a member of a class or trait?
3232
*/
3333
def defKind(tree: Tree): FlagSet = unsplice(tree) match {
34-
case EmptyTree | _: Import => NoInitsInterface
35-
case tree: TypeDef => if (tree.isClassDef) NoInits else NoInitsInterface
36-
case tree: DefDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else NoInits
37-
case tree: ValDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
38-
case _ => EmptyFlags
34+
case EmptyTree | _: Import =>
35+
NoInitsInterface
36+
case tree: TypeDef =>
37+
if (tree.isClassDef) NoInits else NoInitsInterface
38+
case tree: DefDef =>
39+
if (tree.unforcedRhs == EmptyTree && tree.vparamss.forall(_.forall(_.unforcedRhs == EmptyTree))) NoInitsInterface else NoInits
40+
case tree: ValDef =>
41+
if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
42+
case _ =>
43+
EmptyFlags
3944
}
4045

4146
def isOpAssign(tree: Tree) = unsplice(tree) match {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait Foo {
2+
def newName(prefix: String = "foo"): String
3+
}

0 commit comments

Comments
 (0)