File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,15 @@ class TypeUtils:
145
145
case defn.NamedTuple (_, _) => true
146
146
case _ => false
147
147
148
+ def derivesFromNamedTuple (using Context ): Boolean = self match
149
+ case defn.NamedTuple (_, _) => true
150
+ case tp : MatchType =>
151
+ tp.bound.derivesFromNamedTuple || tp.reduced.derivesFromNamedTuple
152
+ case tp : TypeProxy => tp.superType.derivesFromNamedTuple
153
+ case tp : AndType => tp.tp1.derivesFromNamedTuple || tp.tp2.derivesFromNamedTuple
154
+ case tp : OrType => tp.tp1.derivesFromNamedTuple && tp.tp2.derivesFromNamedTuple
155
+ case _ => false
156
+
148
157
/** Drop all named elements in tuple type */
149
158
def stripNamedTuple (using Context ): Type = self.normalized.dealias match
150
159
case defn.NamedTuple (_, vals) =>
Original file line number Diff line number Diff line change @@ -4641,7 +4641,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4641
4641
case _ : SelectionProto =>
4642
4642
tree // adaptations for selections are handled in typedSelect
4643
4643
case _ if ctx.mode.is(Mode .ImplicitsEnabled ) && tree.tpe.isValueType =>
4644
- if tree.tpe.widen.isNamedTupleType && pt.derivesFrom(defn.TupleClass ) then
4644
+ if tree.tpe.derivesFromNamedTuple && pt.derivesFrom(defn.TupleClass ) then
4645
4645
readapt(typed(untpd.Select (untpd.TypedSplice (tree), nme.toTuple)))
4646
4646
else if pt.isRef(defn.AnyValClass , skipRefined = false )
4647
4647
|| pt.isRef(defn.ObjectClass , skipRefined = false )
Original file line number Diff line number Diff line change
1
+ type Person = (name : String , age : Int )
2
+
3
+ val Bob : Person = (name = " Bob" , age = 33 )
4
+
5
+ type SI = (String , Int )
6
+
7
+ def id [X ](x : X ): X = x
8
+ val x : (String , Int ) = Bob
9
+ val y : SI = id(Bob )
10
+ val and : Person & String = ???
11
+ val _: SI = and
12
+ val or : Person | (name : " Bob" , age : 33 ) = ???
13
+ val _: SI = or
14
+
15
+ class C [P <: Person ](p : P ):
16
+ val x : (String , Int ) = p
17
+
18
+
19
+
20
+
You can’t perform that action at this time.
0 commit comments