File tree 6 files changed +71
-5
lines changed
compiler/src/dotty/tools/dotc/sbt
tests/pos-java-interop/i13575 6 files changed +71
-5
lines changed Original file line number Diff line number Diff line change @@ -453,18 +453,20 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
453
453
private abstract class TypeDependencyTraverser (using Context ) extends TypeTraverser () {
454
454
protected def addDependency (symbol : Symbol ): Unit
455
455
456
- val seen = new mutable.HashSet [Type ]
456
+ // Avoid cycles by remembering both the types (testcase:
457
+ // tests/run/enum-values.scala) and the symbols of named types (testcase:
458
+ // tests/pos-java-interop/i13575) we've seen before.
459
+ val seen = new mutable.HashSet [Symbol | Type ]
457
460
def traverse (tp : Type ): Unit = if (! seen.contains(tp)) {
458
461
seen += tp
459
462
tp match {
460
463
case tp : NamedType =>
461
464
val sym = tp.symbol
462
- if (! sym.is(Package )) {
465
+ if ! seen.contains(sym) && ! sym.is(Package ) then
466
+ seen += sym
463
467
addDependency(sym)
464
- if (! sym.isClass)
465
- traverse(tp.info)
468
+ if ! sym.isClass then traverse(tp.info)
466
469
traverse(tp.prefix)
467
- }
468
470
case tp : ThisType =>
469
471
traverse(tp.underlying)
470
472
case tp : ConstantType =>
Original file line number Diff line number Diff line change
1
+ package com .lamoroso .example ;
2
+
3
+ import java .util .Collections ;
4
+ import java .util .List ;
5
+
6
+ public abstract class Builder <T extends Builder <T , R >, R > {
7
+
8
+ private List <String > pools ;
9
+
10
+ public Builder <T , R > withPool (String ... pools ) {
11
+ Collections .addAll (this .pools , pools );
12
+ return this ;
13
+ }
14
+
15
+ public Builder <T , R > build (){return null ;}
16
+ }
Original file line number Diff line number Diff line change
1
+ package com .lamoroso .example ;
2
+
3
+ public class Client {
4
+
5
+ public static Builder <?, ?> builder () {
6
+ return null ;
7
+ }
8
+
9
+ }
Original file line number Diff line number Diff line change
1
+ package com .lamoroso .example ;
2
+
3
+ public class RestClient {
4
+
5
+ private Object instance ;
6
+
7
+ public RestClient (Object instance ) {
8
+ this .instance = instance ;
9
+ }
10
+
11
+ public static RestClientBuilder <?,?> builder () {
12
+ return new RestClientBuilder ();
13
+ }
14
+
15
+ }
Original file line number Diff line number Diff line change
1
+ package com .lamoroso .example ;
2
+
3
+ public class RestClientBuilder <T extends Builder <T , R >, R > {
4
+
5
+ private Builder <?, ?> wrappedBuilder ;
6
+
7
+ protected RestClientBuilder () {
8
+ this .wrappedBuilder = Client .builder ();
9
+ }
10
+
11
+ public RestClientBuilder <T , R > withPool (String ... pools ) {
12
+ this .wrappedBuilder .withPool (pools );
13
+ return this ;
14
+ }
15
+
16
+ public RestClient build () {
17
+ return new RestClient (wrappedBuilder .build ());
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package com .lamoroso .example
2
+
3
+ object ScalaApp extends App {
4
+ RestClient .builder().withPool(" hello" ).build()
5
+ }
You can’t perform that action at this time.
0 commit comments