Skip to content

Commit 665f6d7

Browse files
Florian3kjchyb
andauthored
Scaladoc: fixes and improvements to context bounds and extension methods (#22156)
Closes #21662 More specifically: - Fixed issue with ambiguity of type params in right-associative extension methods (see `\:` and `\\:` in `extensionMethodSignatures.scala`, also see #22170) - Fixed issue with context bounds in type parameters in extensions (`><` in `extensionMethodSignatures.scala`) Additionally fixed and improved simplifying of type lambdas (`TypesSupport.scala`) Removed `MemberInfo` and `unwrapMemberInfo`, which were quite complicated, doing several things at the same time and caused `parseMember` to have two sources of truth. --------- Co-authored-by: Jan Chyb <[email protected]>
1 parent 3435ddb commit 665f6d7

File tree

9 files changed

+295
-287
lines changed

9 files changed

+295
-287
lines changed

scaladoc-testcases/src/tests/classSignatureTestSource.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ abstract class Documentation[T, A <: Int, B >: String, -X, +Y](c1: String, val c
1717
def this(x: T)
1818
= this()
1919

20+
//expected: def toArray[B >: T : ClassTag]: Array[B]
21+
2022
class innerDocumentationClass
2123
{
2224

2325
}
2426

2527
sealed trait CaseImplementThis(id: Int)
2628

27-
case class IAmACaseClass(x: T, id: Int) extends CaseImplementThis/*<-*/(id)/*->*/
29+
case class IAmACaseClass(x: T, id: Int) extends CaseImplementThis(id) //expected: case class IAmACaseClass(x: Documentation.this.T, id: Int) extends CaseImplementThis
30+
31+
case class IAmACaseClassWithParam[T](x: Documentation.this.T, id: T)
2832

2933
case object IAmACaseObject extends CaseImplementThis/*<-*/(0)/*->*/
3034

scaladoc-testcases/src/tests/contextBounds.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ package contextBounds
44
import scala.reflect.ClassTag
55

66
class A:
7+
type :+:[X, Y] = [Z] =>> Map[Z, (X, Y)]
8+
9+
extension [T : ([X] =>> String) : ([X] =>> Int)](x: Int)
10+
def foo[U : ([X] =>> String)](y: Int): Nothing
11+
= ???
12+
def bar[W : T match { case String => List case Int => Option } : Set]: Nothing
13+
= ???
14+
def baz[V : Int :+: String : Option]: Nothing
15+
= ???
16+
717
def basic[A : ClassTag]: A
818
= ???
919

@@ -35,5 +45,5 @@ class A:
3545
// = 1
3646

3747
class Outer[A]:
38-
def falsePositiveInner[T](implicit evidence$3: ClassTag[A]): Int
39-
= 1
48+
def falsePositiveInner[T](implicit evidence$3: ClassTag[A]): Int //expected: def falsePositiveInner[T]: Int
49+
= 1

scaladoc-testcases/src/tests/exports1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class A: //unexpected
1414
= 1
1515
var aVar1: 1
1616
= 1
17-
type HKT[T[_], X] //expected: final type HKT = [T[_], X] =>> a.HKT[T, X]
17+
type HKT[T[_], X] //expected: final type HKT = a.HKT
1818
= T[X]
1919
type SomeRandomType = (List[?] | Seq[?]) & String //expected: final type SomeRandomType = a.SomeRandomType
20-
def x[T[_], X](x: X): HKT[T, X] //expected: def x[T[_], X](x: X): A.this.HKT[T, X]
20+
def x[T[_], X](x: X): HKT[T, X]
2121
= ???
2222
def fn[T, U]: T => U
2323
= ???
2424
object Object //expected: val Obj: Object.type
25-
val x: HKT[List, Int] //expected: val x: A.this.HKT[List, Int]
25+
val x: HKT[List, Int]
2626
= ???
2727
class Class(val a: Int, val b: Int) extends Serializable //expected: final type Class = a.Class
2828
enum Enum: //expected: final type Enum = a.Enum

scaladoc-testcases/src/tests/extensionMethodSignatures.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,23 @@ case class ClassTwo(a: String, b: String)
4444

4545
}
4646

47-
class ClassOneTwo extends ClassOne
47+
class ClassOneTwo extends ClassOne
48+
49+
trait C[T]
50+
trait Equiv[T]:
51+
extension [U : C](x: U)
52+
def ><[V](y: V): Nothing
53+
= ???
54+
55+
trait Monoid[T]:
56+
extension (a: T)
57+
def \:[U](b: U): Nothing
58+
= ???
59+
extension [U](a: T)
60+
def \\:(b: U): Nothing
61+
= ???
62+
63+
class Clazz[U]:
64+
extension [T : ([X] =>> String) : ([X] =>> String)](x: Int)
65+
def bar[U : ([X] =>> String) : List](y: Int): Nothing
66+
= ???
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package tests
2+
package innerClasses
3+
4+
trait A:
5+
def baz: B
6+
= baz2
7+
def baz2: A.this.B //expected: def baz2: B
8+
= baz
9+
type B
10+
class C extends A:
11+
def foo: A.this.B
12+
= ???
13+
def foo2: B
14+
= ???
15+
def bar: B
16+
= ???
17+
18+
class T1:
19+
trait T
20+
class T2:
21+
trait T
22+
class Impl extends T1.this.T //expected: class Impl extends T
23+
// we get rid of the this-type above,
24+
// as ambiguity created by removing this-types is alleviated by links
25+
// (but this can be changed if needed)
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
package tests
22
package thisType
33

4-
// issue 16024
54

65
class X[Map[_, _[_]]]:
6+
// issue 16024
77
inline def map[F[_]](f: [t] => t => F[t]): Map[this.type, F]
88
= ???
9+
10+
sealed trait Tuple[Y[_]]:
11+
def ++[This >: this.type <: Tuple[Y]](that: Y[Tuple[Y]]): Any
12+
= ???
13+
14+
sealed trait NonEmptyTuple extends Tuple[Option]
15+
//expected: def ++[This >: this.type <: Tuple[Option]](that: Option[Tuple[Option]]): Any
16+
17+
trait Foo[X]:
18+
def foo0[T <: Foo.this.type](x: X): Foo.this.type //expected: def foo0[T <: this.type](x: X): this.type
19+
= bar0[T](x)
20+
def bar0[T <: this.type](x: X): this.type
21+
= foo0[T](x)
22+
23+
sealed abstract class Nested[+H, +T <: (Tuple), A <: Tuple[List]] extends NonEmptyTuple, Foo[Int]:
24+
// ^^^^^^^ TODO fix
25+
//expected: def ++[This >: this.type <: Tuple[Option]](that: Option[Tuple[Option]]): Any
26+
27+
//expected: def foo0[T <: this.type](x: Int): this.type
28+
29+
//expected: def bar0[T <: this.type](x: Int): this.type
30+
31+
def foo1[T <: Foo.this.type]: Nothing
32+
= ???
33+
34+
def foo2[T <: this.type]: Nothing
35+
= ???

0 commit comments

Comments
 (0)