Skip to content

Commit fc46e5c

Browse files
committed
Make sure we don't lose erased in method types on Setup
1 parent ca0a6f9 commit fc46e5c

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/Setup.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,16 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
523523
// substitute `x.f.type`, `x` becomes a `TermParamRef`. But the new method
524524
// type is still under initialization and `paramInfos` is still `null`,
525525
// so the new `NamedType` will not have a denoation.
526+
def adaptedInfo(psym: Symbol, info: mt.PInfo): mt.PInfo = mt.companion match
527+
case mtc: MethodTypeCompanion => mtc.adaptParamInfo(psym, info).asInstanceOf[mt.PInfo]
528+
case _ => info
526529
mt.companion(mt.paramNames)(
527530
mt1 =>
528531
if !paramSignatureChanges && !mt.isParamDependent && prevLambdas.isEmpty then
529532
mt.paramInfos
530533
else
531534
val subst = SubstParams(psyms :: prevPsymss, mt1 :: prevLambdas)
532-
psyms.map(psym => subst(psym.nextInfo).asInstanceOf[mt.PInfo]),
535+
psyms.map(psym => adaptedInfo(psym, subst(psym.nextInfo).asInstanceOf[mt.PInfo])),
533536
mt1 =>
534537
integrateRT(mt.resType, psymss.tail, resType, psyms :: prevPsymss, mt1 :: prevLambdas)
535538
)

Diff for: compiler/src/dotty/tools/dotc/core/Types.scala

+19-15
Original file line numberDiff line numberDiff line change
@@ -4178,24 +4178,28 @@ object Types extends TypeUtils {
41784178
* - wrap types of parameters that have an @allowConversions annotation with Into[_]
41794179
*/
41804180
def fromSymbols(params: List[Symbol], resultType: Type)(using Context): MethodType =
4181+
apply(params.map(_.name.asTermName))(
4182+
tl => params.map(p => tl.integrate(params, adaptParamInfo(p))),
4183+
tl => tl.integrate(params, resultType))
4184+
4185+
/** Adapt info of parameter symbol to be integhrated into corresponding MethodType
4186+
* using the scheme described in `fromSymbols`.
4187+
*/
4188+
def adaptParamInfo(param: Symbol, pinfo: Type)(using Context): Type =
41814189
def addAnnotation(tp: Type, cls: ClassSymbol, param: Symbol): Type = tp match
41824190
case ExprType(resType) => ExprType(addAnnotation(resType, cls, param))
41834191
case _ => AnnotatedType(tp, Annotation(cls, param.span))
4184-
4185-
def paramInfo(param: Symbol) =
4186-
var paramType = param.info
4187-
.annotatedToRepeated
4188-
.mapIntoAnnot(defn.IntoAnnot, defn.IntoParamAnnot)
4189-
if param.is(Inline) then
4190-
paramType = addAnnotation(paramType, defn.InlineParamAnnot, param)
4191-
if param.is(Erased) then
4192-
paramType = addAnnotation(paramType, defn.ErasedParamAnnot, param)
4193-
paramType
4194-
4195-
apply(params.map(_.name.asTermName))(
4196-
tl => params.map(p => tl.integrate(params, paramInfo(p))),
4197-
tl => tl.integrate(params, resultType))
4198-
end fromSymbols
4192+
var paramType = pinfo
4193+
.annotatedToRepeated
4194+
.mapIntoAnnot(defn.IntoAnnot, defn.IntoParamAnnot)
4195+
if param.is(Inline) then
4196+
paramType = addAnnotation(paramType, defn.InlineParamAnnot, param)
4197+
if param.is(Erased) then
4198+
paramType = addAnnotation(paramType, defn.ErasedParamAnnot, param)
4199+
paramType
4200+
4201+
def adaptParamInfo(param: Symbol)(using Context): Type =
4202+
adaptParamInfo(param, param.info)
41994203

42004204
def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(using Context): MethodType =
42014205
checkValid(unique(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp, self)))

Diff for: tests/pos-custom-args/captures/erased-methods.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import language.experimental.saferExceptions
2+
import language.experimental.erasedDefinitions
3+
import language.experimental.captureChecking
4+
5+
class Ex1 extends Exception("Ex1")
6+
class Ex2 extends Exception("Ex2")
7+
class Ex3 extends Exception("Ex3")
8+
9+
def foo8a(i: Int) =
10+
(erased xx1: CanThrow[Ex2]^) ?=> throw new Ex2
11+
12+
def foo9a(i: Int)
13+
: (erased x$0: CanThrow[Ex3]^)
14+
?=> (erased x$1: CanThrow[Ex2]^)
15+
?=> (erased x$2: CanThrow[Ex1]^)
16+
?=> Unit
17+
= (erased x$1: CanThrow[Ex3]^)
18+
?=> (erased x$2: CanThrow[Ex2]^)
19+
?=> (erased x$3: CanThrow[Ex1]^)
20+
?=> throw new Ex3

0 commit comments

Comments
 (0)