File tree Expand file tree Collapse file tree 3 files changed +32
-5
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -125,14 +125,26 @@ object Inliner {
125
125
}
126
126
127
127
/** For a retained inline method: The inline expansion of the call to itself with its
128
- * parameters as arguments.
128
+ * parameters as arguments. Given an inline method
129
+ *
130
+ * inline def f[Ts](xs: Us) = body
131
+ *
132
+ * This sets up the call
133
+ *
134
+ * f[Ts'](xs')
135
+ *
136
+ * where the 'ed parameters are copies of the original ones. The call is
137
+ * then inline processed in a context which has a clone f' of f as owner.
138
+ * The cloning of owner and parameters is necessary since otherwise the
139
+ * inliner gets confused in various ways. The inlined body is then
140
+ * transformed back by replacing cloned versions of parameters with original
141
+ * and replacing the cloned owner f' with f.
129
142
*/
130
143
def inlineSelfCall (mdef : DefDef )(using ctx : Context ): Tree =
131
144
val meth = mdef.symbol
132
145
val origParams : List [Symbol ] = mdef.tparams.map(_.symbol) ::: mdef.vparamss.flatten.map(_.symbol)
133
146
val callParams : List [Symbol ] = origParams.map(_.copy())
134
147
val callOwner = meth.copy(flags = meth.flags &~ Inline )
135
- assert(ctx.owner != meth)
136
148
inlineCall(
137
149
ref(meth)
138
150
.appliedToTypes(mdef.tparams.tpes)
Original file line number Diff line number Diff line change @@ -2939,9 +2939,13 @@ class Typer extends Namer
2939
2939
! suppressInline) {
2940
2940
tree.tpe <:< wildApprox(pt)
2941
2941
val errorCount = ctx.reporter.errorCount
2942
- val inlined = Inliner .inlineCall(tree)
2943
- if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined)
2944
- else inlined
2942
+ val meth = methPart(tree).symbol
2943
+ if meth.is(Deferred ) then
2944
+ errorTree(tree, i " Deferred inline ${meth.showLocated} cannot be invoked " )
2945
+ else
2946
+ val inlined = Inliner .inlineCall(tree)
2947
+ if ((inlined ne tree) && errorCount == ctx.reporter.errorCount) readaptSimplified(inlined)
2948
+ else inlined
2945
2949
}
2946
2950
else if (tree.symbol.isScala2Macro &&
2947
2951
// raw and s are eliminated by the StringInterpolatorOpt phase
Original file line number Diff line number Diff line change
1
+ class A :
2
+ inline def f (): Int
3
+
4
+ class B extends A :
5
+ inline def f () = 1
6
+
7
+ def Test =
8
+ val b = B ()
9
+ println(b.f()) // ok
10
+ val a : A = b
11
+ println(a.f()) // error: Deferred inline method f in class A cannot be invoked
You can’t perform that action at this time.
0 commit comments