Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes involving SAM types #10979

Merged
merged 3 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class Compiler {
new CookComments, // Cook the comments: expand variables, doc, etc.
new CheckStatic, // Check restrictions that apply to @static members
new BetaReduce, // Reduce closure applications
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
new init.Checker) :: // Check initialization of objects
List(new ElimRepeated, // Rewrite vararg parameters and arguments
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
new ProtectedAccessors, // Add accessors for protected members
new ExtensionMethods, // Expand methods of value classes with extension methods
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
val constr = newConstructor(cls, Synthetic, Nil, Nil).entered
def forwarder(fn: TermSymbol, name: TermName) = {
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final).entered.asTerm
if (fwdMeth.allOverriddenSymbols.exists(!_.is(Deferred))) fwdMeth.setFlag(Override)
for overridden <- fwdMeth.allOverriddenSymbols do
if overridden.is(Extension) then fwdMeth.setFlag(Extension)
if !overridden.is(Deferred) then fwdMeth.setFlag(Override)
polyDefDef(fwdMeth, tprefs => prefss => ref(fn).appliedToTypes(tprefs).appliedToArgss(prefss))
}
val forwarders = fns.lazyZip(methNames).map(forwarder)
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5006,7 +5006,9 @@ object Types {
mapOver(tp)
}
}
val approx = approxParams(mt).asInstanceOf[MethodType]
val approx =
if ctx.owner.isContainedIn(cls) then mt
else approxParams(mt).asInstanceOf[MethodType]
Some(approx)
case _ =>
None
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/ByNameClosures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class ByNameClosures extends TransformByNameApply with IdentityDenotTransformer

override def phaseName: String = ByNameClosures.name

override def runsAfterGroupsOf: Set[String] = Set(ExpandSAMs.name)
// ExpanSAMs applied to partial functions creates methods that need
// to be fully defined before converting. Test case is pos/i9391.scala.

override def mkByNameClosure(arg: Tree, argType: Type)(using Context): Tree = {
val meth = newSymbol(
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType))
Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i9391.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def g(x: => Any): Any = x

val a: PartialFunction[Any => Any, Any] = (f => g(f(0)) match { case v => v }) // was an error, now OK