Skip to content

Commit

Permalink
Merge pull request scala#11838 from dotty-staging/fix-10927
Browse files Browse the repository at this point in the history
Fix name generation for anonymous given of infix types.
  • Loading branch information
smarter authored Mar 22, 2021
2 parents 75f7cb3 + 87e03b2 commit 45b35b3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,16 @@ object desugar {
case tree: TypeDef => tree.name.toString
case tree: AppliedTypeTree if followArgs && tree.args.nonEmpty =>
s"${apply(x, tree.tpt)}_${extractArgs(tree.args)}"
case InfixOp(left, op, right) =>
if followArgs then s"${op.name}_${extractArgs(List(left, right))}"
else op.name.toString
case tree: LambdaTypeTree =>
apply(x, tree.body)
case tree: Tuple =>
extractArgs(tree.trees)
case tree: Function if tree.args.nonEmpty =>
if (followArgs) s"${extractArgs(tree.args)}_to_${apply("", tree.body)}" else "Function"
if followArgs then s"${extractArgs(tree.args)}_to_${apply("", tree.body)}"
else "Function"
case _ => foldOver(x, tree)
}
else x
Expand Down
23 changes: 23 additions & 0 deletions tests/neg/i10927.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
trait Transition[From, To]

infix type ==>[From, To] = Transition[From, To]

type A = A.type
object A

type B = B.type
object B

type C = C.type
object C

// Compiles
given (A ==> B) = ???

// was Compile error
given (A ==> C) = ???

given ==>[A, C] = ??? // error: double definition

given List[A ==> B] = ???
given List[A ==> C] = ??? // error: double definition
18 changes: 18 additions & 0 deletions tests/pos/i10927.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Transition[From, To]

infix type ==>[From, To] = Transition[From, To]

type A = A.type
object A

type B = B.type
object B

type C = C.type
object C

// Compiles
given (A ==> B) = ???

// was Compile error
given (A ==> C) = ???
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/Enums.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ object Enums/*<-_empty_::Enums.*/:
case Refl/*<-_empty_::Enums.`<:<`.Refl#*/[C/*<-_empty_::Enums.`<:<`.Refl#[C]*/]() extends (C/*->_empty_::Enums.`<:<`.Refl#[C]*/ <:</*->_empty_::Enums.`<:<`#*/ C/*->_empty_::Enums.`<:<`.Refl#[C]*/)

object <:</*<-_empty_::Enums.`<:<`.*/ :
given [T]: (T/*<-_empty_::Enums.`<:<`.given_T().*//*<-_empty_::Enums.`<:<`.given_T().[T]*//*->_empty_::Enums.`<:<`.given_T().[T]*/ <:</*->_empty_::Enums.`<:<`#*/ T/*->_empty_::Enums.`<:<`.given_T().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/()
given [T]: (T <:< T/*<-_empty_::Enums.`<:<`.`given_<:<_T_T`().*//*<-_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*//*->_empty_::Enums.`<:<`#*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/()

extension [A/*<-_empty_::Enums.unwrap().[A]*/, B/*<-_empty_::Enums.unwrap().[B]*/](opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) def unwrap/*<-_empty_::Enums.unwrap().*/(using ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:</*->_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]): Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match
case Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.unapply().*/() => opt/*->_empty_::Enums.unwrap().(opt)*/.flatMap/*->scala::Option#flatMap().*/(identity/*->scala::Predef.identity().*//*->local0*/[Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]])

val some1/*<-_empty_::Enums.some1.*/ = Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.unwrap().*//*->_empty_::Enums.`<:<`.given_T().*/
val some1/*<-_empty_::Enums.some1.*/ = Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.unwrap().*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().*/

enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#`<init>`().*/:
private final val G/*<-_empty_::Enums.Planet#G.*/ = 6.67300E-11
Expand Down
14 changes: 7 additions & 7 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ _empty_/Enums.`<:<`.Refl.toString(). => method toString
_empty_/Enums.`<:<`.Refl.unapply(). => method unapply
_empty_/Enums.`<:<`.Refl.unapply().(x$1) => param x$1
_empty_/Enums.`<:<`.Refl.unapply().[C] => typeparam C
_empty_/Enums.`<:<`.`given_<:<_T_T`(). => final implicit method given_<:<_T_T
_empty_/Enums.`<:<`.`given_<:<_T_T`().[T] => typeparam T
_empty_/Enums.`<:<`.fromOrdinal(). => method fromOrdinal
_empty_/Enums.`<:<`.fromOrdinal().(ordinal) => param ordinal
_empty_/Enums.`<:<`.given_T(). => final implicit method given_T
_empty_/Enums.`<:<`.given_T().[T] => typeparam T
_empty_/Enums.some1. => val method some1
_empty_/Enums.unwrap(). => method unwrap
_empty_/Enums.unwrap().(ev) => implicit param ev
Expand Down Expand Up @@ -962,11 +962,11 @@ Occurrences:
[46:34..46:35): C -> _empty_/Enums.`<:<`.Refl#[C]
[46:35..46:35): -> _empty_/Enums.`<:<`#`<init>`().
[48:9..48:12): <:< <- _empty_/Enums.`<:<`.
[49:10..49:17): [T]: (T <- _empty_/Enums.`<:<`.given_T().
[49:11..49:12): T <- _empty_/Enums.`<:<`.given_T().[T]
[49:16..49:17): T -> _empty_/Enums.`<:<`.given_T().[T]
[49:10..49:23): [T]: (T <:< T <- _empty_/Enums.`<:<`.`given_<:<_T_T`().
[49:11..49:12): T <- _empty_/Enums.`<:<`.`given_<:<_T_T`().[T]
[49:16..49:17): T -> _empty_/Enums.`<:<`.`given_<:<_T_T`().[T]
[49:18..49:21): <:< -> _empty_/Enums.`<:<`#
[49:22..49:23): T -> _empty_/Enums.`<:<`.given_T().[T]
[49:22..49:23): T -> _empty_/Enums.`<:<`.`given_<:<_T_T`().[T]
[49:27..49:31): Refl -> _empty_/Enums.`<:<`.Refl.
[49:31..49:31): -> _empty_/Enums.`<:<`.Refl.apply().
[51:13..51:14): A <- _empty_/Enums.unwrap().[A]
Expand Down Expand Up @@ -997,7 +997,7 @@ Occurrences:
[54:19..54:23): Some -> scala/Some.
[54:23..54:23): -> scala/Some.apply().
[54:28..54:34): unwrap -> _empty_/Enums.unwrap().
[54:34..54:34): -> _empty_/Enums.`<:<`.given_T().
[54:34..54:34): -> _empty_/Enums.`<:<`.`given_<:<_T_T`().
[56:7..56:13): Planet <- _empty_/Enums.Planet#
[56:13..56:13): <- _empty_/Enums.Planet#`<init>`().
[56:14..56:18): mass <- _empty_/Enums.Planet#mass.
Expand Down

0 comments on commit 45b35b3

Please sign in to comment.