Skip to content

Commit 7c2a76b

Browse files
committed
Make sure we don't lose erased in method types on Setup
1 parent fcf4045 commit 7c2a76b

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,16 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
535535
// substitute `x.f.type`, `x` becomes a `TermParamRef`. But the new method
536536
// type is still under initialization and `paramInfos` is still `null`,
537537
// so the new `NamedType` will not have a denoation.
538+
def adaptedInfo(psym: Symbol, info: mt.PInfo): mt.PInfo = mt.companion match
539+
case mtc: MethodTypeCompanion => mtc.adaptParamInfo(psym, info).asInstanceOf[mt.PInfo]
540+
case _ => info
538541
mt.companion(mt.paramNames)(
539542
mt1 =>
540543
if !paramSignatureChanges && !mt.isParamDependent && prevLambdas.isEmpty then
541544
mt.paramInfos
542545
else
543546
val subst = SubstParams(psyms :: prevPsymss, mt1 :: prevLambdas)
544-
psyms.map(psym => subst(psym.nextInfo).asInstanceOf[mt.PInfo]),
547+
psyms.map(psym => adaptedInfo(psym, subst(psym.nextInfo).asInstanceOf[mt.PInfo])),
545548
mt1 =>
546549
integrateRT(mt.resType, psymss.tail, resType, psyms :: prevPsymss, mt1 :: prevLambdas)
547550
)

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

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

41974201
def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(using Context): MethodType =
41984202
checkValid(unique(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp, self)))
Lines changed: 20 additions & 0 deletions
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)