Skip to content

Commit 2be0707

Browse files
authored
Merge pull request #10979 from dotty-staging/fix-#9391
Fixes involving SAM types
2 parents d35f182 + 57b5311 commit 2be0707

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Compiler {
6161
new CookComments, // Cook the comments: expand variables, doc, etc.
6262
new CheckStatic, // Check restrictions that apply to @static members
6363
new BetaReduce, // Reduce closure applications
64+
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
6465
new init.Checker) :: // Check initialization of objects
6566
List(new ElimRepeated, // Rewrite vararg parameters and arguments
66-
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
6767
new ProtectedAccessors, // Add accessors for protected members
6868
new ExtensionMethods, // Expand methods of value classes with extension methods
6969
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
350350
val constr = newConstructor(cls, Synthetic, Nil, Nil).entered
351351
def forwarder(fn: TermSymbol, name: TermName) = {
352352
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final).entered.asTerm
353-
if (fwdMeth.allOverriddenSymbols.exists(!_.is(Deferred))) fwdMeth.setFlag(Override)
353+
for overridden <- fwdMeth.allOverriddenSymbols do
354+
if overridden.is(Extension) then fwdMeth.setFlag(Extension)
355+
if !overridden.is(Deferred) then fwdMeth.setFlag(Override)
354356
polyDefDef(fwdMeth, tprefs => prefss => ref(fn).appliedToTypes(tprefs).appliedToArgss(prefss))
355357
}
356358
val forwarders = fns.lazyZip(methNames).map(forwarder)

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5006,7 +5006,9 @@ object Types {
50065006
mapOver(tp)
50075007
}
50085008
}
5009-
val approx = approxParams(mt).asInstanceOf[MethodType]
5009+
val approx =
5010+
if ctx.owner.isContainedIn(cls) then mt
5011+
else approxParams(mt).asInstanceOf[MethodType]
50105012
Some(approx)
50115013
case _ =>
50125014
None

compiler/src/dotty/tools/dotc/transform/ByNameClosures.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class ByNameClosures extends TransformByNameApply with IdentityDenotTransformer
2626

2727
override def phaseName: String = ByNameClosures.name
2828

29+
override def runsAfterGroupsOf: Set[String] = Set(ExpandSAMs.name)
30+
// ExpanSAMs applied to partial functions creates methods that need
31+
// to be fully defined before converting. Test case is pos/i9391.scala.
32+
2933
override def mkByNameClosure(arg: Tree, argType: Type)(using Context): Tree = {
3034
val meth = newSymbol(
3135
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType))

tests/pos/i9391.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def g(x: => Any): Any = x
2+
3+
val a: PartialFunction[Any => Any, Any] = (f => g(f(0)) match { case v => v }) // was an error, now OK

0 commit comments

Comments
 (0)