File tree Expand file tree Collapse file tree 6 files changed +59
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 6 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -302,7 +302,7 @@ trait ConstraintHandling[AbstractContext] {
302302 if (isMultiSingleton(tp) && ! isMultiSingleton(bound) &&
303303 ! isSubTypeWhenFrozen(bound, defn.SingletonType )) tp.widen
304304 else tp
305- widenOr(widenSingle(tp))
305+ widenOr(widenSingle(tp)).dropRepeatedAnnot
306306 }
307307
308308 /** The instance type of `param` in the current constraint (which contains `param`).
Original file line number Diff line number Diff line change @@ -1485,6 +1485,13 @@ object Types {
14851485 */
14861486 def signature (implicit ctx : Context ): Signature = Signature .NotAMethod
14871487
1488+ def dropRepeatedAnnot (implicit ctx : Context ): Type = this match {
1489+ case AnnotatedType (parent, annot) if annot.symbol eq defn.RepeatedAnnot => parent
1490+ case tp @ AnnotatedType (parent, annot) =>
1491+ tp.derivedAnnotatedType(parent.dropRepeatedAnnot, annot)
1492+ case tp => tp
1493+ }
1494+
14881495 def annotatedToRepeated (implicit ctx : Context ): Type = this match {
14891496 case tp @ ExprType (tp1) => tp.derivedExprType(tp1.annotatedToRepeated)
14901497 case AnnotatedType (tp, annot) if annot matches defn.RepeatedAnnot =>
Original file line number Diff line number Diff line change @@ -1320,10 +1320,13 @@ class Namer { typer: Typer =>
13201320 // Widen rhs type and eliminate `|' but keep ConstantTypes if
13211321 // definition is inline (i.e. final in Scala2) and keep module singleton types
13221322 // instead of widening to the underlying module class types.
1323- def widenRhs (tp : Type ): Type = tp.widenTermRefExpr match {
1324- case ctp : ConstantType if isInlineVal => ctp
1325- case ref : TypeRef if ref.symbol.is(ModuleClass ) => tp
1326- case _ => tp.widen.widenUnion
1323+ def widenRhs (tp : Type ): Type = {
1324+ val tp1 = tp.widenTermRefExpr match {
1325+ case ctp : ConstantType if isInlineVal => ctp
1326+ case ref : TypeRef if ref.symbol.is(ModuleClass ) => tp
1327+ case _ => tp.widen.widenUnion
1328+ }
1329+ tp1.dropRepeatedAnnot
13271330 }
13281331
13291332 // Replace aliases to Unit by Unit itself. If we leave the alias in
Original file line number Diff line number Diff line change 1+ C.bar1 : scala.Option[scala.collection.Seq[scala.Predef.String]]
2+ C.bar2 : scala.Option[scala.collection.Seq[scala.Predef.String]]
3+ C.foo1 : scala.collection.Seq[scala.Predef.String]
4+ C.foo2 : scala.collection.Seq[scala.Predef.String]
Original file line number Diff line number Diff line change 1+ object Macros {
2+ import scala .quoted ._
3+ import scala .quoted .autolift ._
4+ import scala .tasty ._
5+
6+ inline def go [T ](t : => T ) = $ { impl(' t ) }
7+ def impl [T ](expr : Expr [T ])(implicit reflect : Reflection ): Expr [Unit ] = {
8+ import reflect ._
9+
10+ val tree = expr.unseal
11+
12+ val methods =
13+ tree.tpe.classSymbol.get.classMethods.map { m =>
14+ val name = m.showCode
15+ val returnType = m.tree.returnTpt.tpe.showCode
16+ s " $name : $returnType"
17+ }.sorted
18+
19+ methods.foldLeft(' {}) { (res, m) => ' { $res; println($ {m}) } }
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ class C {
2+ def foo1 (s : String * ) = s
3+ def foo2 (s : String * ) = {
4+ val s1 = s
5+ s
6+ }
7+
8+ def bar1 (s : String * ) = Option (s)
9+ def bar2 (s : String * ) = {
10+ val o = Option (s)
11+ o
12+ }
13+ }
14+
15+ object Test {
16+ def main (args : Array [String ]): Unit = {
17+ Macros .go(new C )
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments