@@ -1236,25 +1236,30 @@ object DFVal extends DFValLP:
12361236 exactOp2[" as" , DFC , DFValAny ](lhs, aliasType)
12371237 end extension
12381238 extension [L ](inline lhs : L )
1239- transparent inline def <~ > [R ](inline rhs : R )(using DFC ): Any =
1239+ transparent inline def <> [R ](inline rhs : R )(using DFC ): Any =
12401240 // operator `<>` as a constructor is unidirectional
12411241 // operator `<>` as a connection is bidirectional and commutative
1242- // TODO: possibly use match on lhs and rhs together fixing scalac issue
1243- // https://github.com/scala/scala3/issues/24076
1244- inline lhs match
1245- case lhs : DFValAny => inline rhs match
1246- // if both LHS and RHS are DFVals, we call `specialConnect` to handle possible
1247- // connection in either direction where both implicit directions are available
1248- // case rhs: DFValAny => ConnectOps.specialConnect(lhs, rhs)
1249- // otherwise, we invoke the implicit given operation in both directions by turning
1250- // on the bothWays flag for all other cases
1251- case _ => exactOp2[" <>" , DFC , Any ](lhs, rhs)
1252- case _ => inline rhs match
1253- // if the RHS is a modifier, this is a port/variable constructor,
1254- // so we invoke the the implicit given operation only in one way
1255- case _ : ModifierAny => exactOp2[" <>" , DFC , Any ](lhs, rhs)
1256- case _ => exactOp2[" <>" , DFC , Any ](lhs, rhs, bothWays = true )
1257- end match
1242+ inline val lhsIsDFVal = inline compiletime.erasedValue[L ] match
1243+ case _ : DFValAny => true
1244+ case _ => false
1245+ inline val rhsIsDFVal = inline compiletime.erasedValue[R ] match
1246+ case _ : DFValAny => true
1247+ case _ => false
1248+ inline val rhsIsModifier = inline compiletime.erasedValue[R ] match
1249+ case _ : ModifierAny => true
1250+ case _ => false
1251+ // if both LHS and RHS are DFVals, we call `specialConnect` to handle possible
1252+ // connection in either direction where both implicit directions are available
1253+ inline if (lhsIsDFVal && rhsIsDFVal)
1254+ inline lhs match
1255+ case lhs : DFValAny => inline rhs match
1256+ case rhs : DFValAny => ConnectOps .specialConnect(lhs, rhs)
1257+ // if the RHS is a modifier, this is a port/variable constructor,
1258+ // so we invoke the the implicit given operation only in one way
1259+ else if (rhsIsModifier) exactOp2[" <>" , DFC , Any ](lhs, rhs)
1260+ // otherwise, we invoke the implicit given operation in both directions by turning
1261+ // on the bothWays flag for all other cases
1262+ else exactOp2[" <>" , DFC , Any ](lhs, rhs, bothWays = true )
12581263 end extension
12591264
12601265 extension [T <: DFTypeAny , A , C , I , S <: Int , V ](dfVal : DFVal [T , Modifier [A , C , I , Any ]])
@@ -1557,21 +1562,22 @@ object ConnectOps:
15571562 inline lhs : L ,
15581563 inline rhs : R
15591564 )(using DFC ): Unit =
1560- inline val connectableL = inline lhs match
1565+ inline val connectableL = inline compiletime.erasedValue[ L ] match
15611566 case _ : DFVal [DFTypeAny , Modifier [Any , Modifier .Connectable , Any , Any ]] => true
15621567 case _ => false
1563- inline val connectableR = inline rhs match
1568+ inline val connectableR = inline compiletime.erasedValue[ R ] match
15641569 case _ : DFVal [DFTypeAny , Modifier [Any , Modifier .Connectable , Any , Any ]] => true
15651570 case _ => false
15661571 inline if (connectableL || connectableR)
15671572 inline if (IsGiven [TC_Connect [L , R ]])
15681573 val tcL = compiletime.summonInline[TC_Connect [L , R ]]
15691574 inline if (IsGiven [TC_Connect [R , L ]])
15701575 val tcR = compiletime.summonInline[TC_Connect [R , L ]]
1571- // since we have both candidates, we try the RHS first, so if both fail at runtime,
1572- // the error message will be from the LHS as fallback.
1573- try tcR.connect(rhs, lhs)
1574- catch case e : Throwable => tcL.connect(lhs, rhs)
1576+ try tcL.connect(lhs, rhs)
1577+ catch
1578+ case eL : Throwable =>
1579+ try tcR.connect(rhs, lhs)
1580+ catch case eR : Throwable => throw eL
15751581 else tcL.connect(lhs, rhs)
15761582 else if (IsGiven [TC_Connect [R , L ]])
15771583 compiletime.summonInline[TC_Connect [R , L ]].connect(rhs, lhs)
@@ -1599,17 +1605,6 @@ object ConnectOps:
15991605 def apply (lhs : L , rhs : R )(using DFC ): Out = trydf {
16001606 lhs.connect(tc(lhs.dfType, rhs))
16011607 }(using dfc, CTName (" <>" ))
1602- extension [T <: DFTypeAny , C ](dfPort : DFVal [T , Modifier [Any , C , Any , Any ]])
1603- def <> (rhs : DFVal .TC_Or_OPEN_Or_Resource .Exact [T ])(using
1604- DFC
1605- )(using
1606- connectableOnly : ConnectableOnly [C , rhs.ExactFrom ]
1607- ): Unit =
1608- given CTName = CTName (" <>" )
1609- trydf {
1610- rhs.tc.connect(dfPort, rhs.exactFrom)
1611- }
1612- end extension
16131608end ConnectOps
16141609
16151610extension (dfVal : ir.DFVal )
0 commit comments