@@ -1058,6 +1058,10 @@ trait Typers extends Modes with Adaptations with Tags {
1058
1058
instantiateToMethodType(mt)
1059
1059
1060
1060
case _ =>
1061
+ def shouldInsertApply (tree : Tree ) = inAllModes(mode, EXPRmode | FUNmode ) && (tree.tpe match {
1062
+ case _ : MethodType | _ : OverloadedType | _ : PolyType => false
1063
+ case _ => applyPossible
1064
+ })
1061
1065
def applyPossible = {
1062
1066
def applyMeth = member(adaptToName(tree, nme.apply), nme.apply)
1063
1067
dyna.acceptsApplyDynamic(tree.tpe) || (
@@ -1071,14 +1075,12 @@ trait Typers extends Modes with Adaptations with Tags {
1071
1075
adaptType()
1072
1076
else if (
1073
1077
inExprModeButNot(mode, FUNmode ) && ! tree.isDef && // typechecking application
1074
- tree.symbol != null && tree.symbol.isTermMacro) // of a macro
1078
+ tree.symbol != null && tree.symbol.isTermMacro && // of a macro
1079
+ ! tree.attachments.get[SuppressMacroExpansionAttachment .type ].isDefined)
1075
1080
macroExpand(this , tree, mode, pt)
1076
1081
else if (inAllModes(mode, PATTERNmode | FUNmode ))
1077
1082
adaptConstrPattern()
1078
- else if (inAllModes(mode, EXPRmode | FUNmode ) &&
1079
- ! tree.tpe.isInstanceOf [MethodType ] &&
1080
- ! tree.tpe.isInstanceOf [OverloadedType ] &&
1081
- applyPossible)
1083
+ else if (shouldInsertApply(tree))
1082
1084
insertApply()
1083
1085
else if (! context.undetparams.isEmpty && ! inPolyMode(mode)) { // (9)
1084
1086
assert(! inHKMode(mode), modeString(mode)) // @M
@@ -3772,9 +3774,14 @@ trait Typers extends Modes with Adaptations with Tags {
3772
3774
case t : ValOrDefDef => t.rhs
3773
3775
case t => t
3774
3776
}
3775
- val (outer, explicitTargs) = cxTree1 match {
3777
+ val cxTree2 = cxTree1 match {
3778
+ case Typed (t, tpe) => t // ignore outer type annotation
3779
+ case t => t
3780
+ }
3781
+ val (outer, explicitTargs) = cxTree2 match {
3776
3782
case TypeApply (fun, targs) => (fun, targs)
3777
3783
case Apply (TypeApply (fun, targs), args) => (Apply (fun, args), targs)
3784
+ case Select (TypeApply (fun, targs), nme) => (Select (fun, nme), targs)
3778
3785
case t => (t, Nil )
3779
3786
}
3780
3787
def hasNamedArg (as : List [Tree ]) = as.collectFirst{case AssignOrNamedArg (lhs, rhs) => }.nonEmpty
@@ -4855,9 +4862,9 @@ trait Typers extends Modes with Adaptations with Tags {
4855
4862
// find out whether the programmer is trying to eta-expand a macro def
4856
4863
// to do that we need to typecheck the tree first (we need a symbol of the eta-expandee)
4857
4864
// that typecheck must not trigger macro expansions, so we explicitly prohibit them
4858
- // Q: "but, " - you may ask - ", `typed1` doesn't call adapt, which does macro expansion, so why explicit check?"
4859
- // A: solely for robustness reasons. this mechanism might change in the future, which might break unprotected code
4860
- val exprTyped = context.withMacrosDisabled( typed1(expr, mode, pt) )
4865
+ // however we cannot do `context.withMacrosDisabled`
4866
+ // because `expr` might contain nested macro calls (see SI-6673)
4867
+ val exprTyped = typed1(expr updateAttachment SuppressMacroExpansionAttachment , mode, pt)
4861
4868
exprTyped match {
4862
4869
case macroDef if macroDef.symbol != null && macroDef.symbol.isTermMacro && ! macroDef.symbol.isErroneous =>
4863
4870
MacroEtaError (exprTyped)
@@ -5001,8 +5008,14 @@ trait Typers extends Modes with Adaptations with Tags {
5001
5008
}
5002
5009
5003
5010
def typedTypeTree (tree : TypeTree ) = {
5004
- if (tree.original != null )
5005
- tree setType typedType(tree.original, mode).tpe
5011
+ if (tree.original != null ) {
5012
+ val newTpt = typedType(tree.original, mode)
5013
+ tree setType newTpt.tpe
5014
+ newTpt match {
5015
+ case tt @ TypeTree () => tree setOriginal tt.original
5016
+ case _ => tree
5017
+ }
5018
+ }
5006
5019
else
5007
5020
// we should get here only when something before failed
5008
5021
// and we try again (@see tryTypedApply). In that case we can assign
0 commit comments