@@ -157,19 +157,31 @@ object desugar {
157157 ValDef (epname, tpt, EmptyTree ).withFlags(paramFlags | Implicit )
158158 }
159159
160- /** Expand context bounds to evidence params. E.g.,
160+ /** 1. Expand context bounds to evidence params. E.g.,
161161 *
162162 * def f[T >: L <: H : B](params)
163163 * ==>
164164 * def f[T >: L <: H](params)(implicit evidence$0: B[T])
165165 *
166- * Expand default arguments to default getters. E.g,
166+ * 2. Expand default arguments to default getters. E.g,
167167 *
168168 * def f[T: B](x: Int = 1)(y: String = x + "m") = ...
169169 * ==>
170170 * def f[T](x: Int)(y: String)(implicit evidence$0: B[T]) = ...
171171 * def f$default$1[T] = 1
172172 * def f$default$2[T](x: Int) = x + "m"
173+ *
174+ * 3. Convert <: T to : T in specializing inline methods. E.g.
175+ *
176+ * inline def f(x: Boolean) <: Any = if (x) 1 else ""
177+ * ==>
178+ * inline def f(x: Boolean): Any = if (x) 1 else ""
179+ *
180+ * 4. Upcast non-specializing inline methods. E.g.
181+ *
182+ * inline def f(x: Boolean): Any = if (x) 1 else ""
183+ * ==>
184+ * inline def f(x: Boolean): Any = (if (x) 1 else ""): Any
173185 */
174186 private def defDef (meth : DefDef , isPrimaryConstructor : Boolean = false )(implicit ctx : Context ): Tree = {
175187 val DefDef (name, tparams, vparamss, tpt, rhs) = meth
@@ -188,7 +200,16 @@ object desugar {
188200 cpy.TypeDef (tparam)(rhs = desugarContextBounds(tparam.rhs))
189201 }
190202
191- val meth1 = addEvidenceParams(cpy.DefDef (meth)(tparams = tparams1), epbuf.toList)
203+ var meth1 = addEvidenceParams(cpy.DefDef (meth)(tparams = tparams1), epbuf.toList)
204+
205+ if (meth1.mods.is(Inline ))
206+ meth1.tpt match {
207+ case TypeBoundsTree (_, tpt1) =>
208+ meth1 = cpy.DefDef (meth1)(tpt = tpt1)
209+ case tpt if ! tpt.isEmpty && ! meth1.rhs.isEmpty =>
210+ meth1 = cpy.DefDef (meth1)(rhs = Typed (meth1.rhs, tpt))
211+ case _ =>
212+ }
192213
193214 /** The longest prefix of parameter lists in vparamss whose total length does not exceed `n` */
194215 def takeUpTo (vparamss : List [List [ValDef ]], n : Int ): List [List [ValDef ]] = vparamss match {
0 commit comments