Repository navigation
Commit b2bb215
committed
WIP - order of resolved variables is wrong
Ref pmd#5441
Below the inference trace.
What happens here is we have the following inference context.
Inference context 7
'a { 'a <: java.lang.String, 'a <: 'e, 'a <: java.lang.Object }
'b { 'b <: java.lang.Object, 'b <: java.lang.Integer }
'e { 'e <: java.lang.Object, 'e >: 'a }
'f { 'f <: java.lang.Object, 'f <: java.lang.Integer }
The dependency graph groups 'a and 'e together, as they depend on one another.
Here is the problem:
- 'a is resolved first. By rule UPPER, it is instantiated to String
- 'e is resolved next. By rule LOWER, it is instantiated to 'a, ie to String.
If the variables were solved in the reverse order, the following would happen:
- 'e is instantiated to Object (by rule UPPER)
- 'a is instantiated to Object (by rule UPPER)
The latter is the javac behavior, which is why I mention this is a problem.
However I do not think our implementation is non-compliant here. The JLS does not
specify the resolution order here AFAICT.
I also didn't dive deep enough in javac to know why it does what it does. It is
possible that it adds a dependency between 'a and 'e to force 'e to be resolved
earlier. It has a system of "stuck" dependencies that we don't have. I believe
It is also possible that this is just happenstance.
To investigate this further, I should look into the dependency graph produced
by javac and understand better what it does here.
---
Phase STRICT newCacheBuilder(java.lang.String) -> Test$CacheBuilder<K, V>
ARGUMENTS
Checking arg 0 against java.lang.String
At: (unknown):22:59
Expr: \"test\"
Success: newCacheBuilder(java.lang.String) -> Test$CacheBuilder<java.lang.String, java.lang.Integer>
Skipping instantiation of Test.<K, V> newCacheBuilder(java.lang.String) -> Test$CacheBuilder<java.lang.String, java.lang.Integer>, it's already complete
Phase STRICT build(Test#CacheLoader<? super K1, V1>) -> Test$Cache<K1, V1>
Changed bound (ctx 3): 'a <: java.lang.String
Changed bound (ctx 3): 'b <: java.lang.Integer
Context 3 build(Test#CacheLoader<? super 'a, 'b>) -> Test$Cache<'a, 'b>
ARGUMENTS
Checking arg 0 against Test#CacheLoader<? super 'a, 'b>
At: (unknown):23:32
Expr: new CacheLoader<>()
Phase STRICT new() -> Test#CacheLoader<K, V>
Context 4 new() -> Test#CacheLoader<'c, 'd>
ARGUMENTS
Solving with context 5 for applicability testing
| Ivar instantiated (ctx 5): 'c := java.lang.Object
| Ivar instantiated (ctx 5): 'd := java.lang.Object
Success: new() -> Test#CacheLoader<'c, 'd>
Phase INVOC_STRICT new() -> Test#CacheLoader<K, V>
Context 6 new() -> Test#CacheLoader<'e, 'f>
RETURN
New bound (ctx 6): 'e >: 'a
New bound (ctx 3): 'b = 'f
ARGUMENTS
New bound (ctx 3): 'a <: 'e
Ctx 3 adopts ['e, 'f] from ctx 6
Success: new() -> Test#CacheLoader<'e, 'f>
New bound (ctx 3): 'f <: java.lang.Integer
Ivar merged (ctx 3): 'b <=> 'f
Solving with context 7 for applicability testing
| Ivar instantiated (ctx 7): 'a := java.lang.String
| New bound (ctx 3): 'e >: java.lang.String
| Ivar instantiated (ctx 7): 'e := java.lang.String
| Ivar instantiated (ctx 7): 'b := java.lang.Integer
Success: build(Test#CacheLoader<? super 'a, 'f>) -> Test$Cache<'a, 'f>
Phase INVOC_STRICT build(Test#CacheLoader<? super K1, V1>) -> Test$Cache<K1, V1>
Changed bound (ctx 8): 'g <: java.lang.String
Changed bound (ctx 8): 'h <: java.lang.Integer
Context 8 build(Test#CacheLoader<? super 'g, 'h>) -> Test$Cache<'g, 'h>
RETURN
ARGUMENTS
Checking arg 0 against Test#CacheLoader<? super 'g, 'h>
At: (unknown):23:32
Expr: new CacheLoader<>()
Phase INVOC_STRICT new() -> Test#CacheLoader<K, V>
Context 9 new() -> Test#CacheLoader<'i, 'j>
RETURN
New bound (ctx 9): 'i >: 'g
New bound (ctx 8): 'h = 'j
ARGUMENTS
New bound (ctx 8): 'g <: 'i
Ctx 8 adopts ['i, 'j] from ctx 9
Success: new() -> Test#CacheLoader<'i, 'j>
New bound (ctx 8): 'j <: java.lang.Integer
Ivar merged (ctx 8): 'h <=> 'j
Ivar instantiated (ctx 8): 'g := java.lang.String
New bound (ctx 8): 'i >: java.lang.String
Ivar instantiated (ctx 8): 'i := java.lang.String
Ivar instantiated (ctx 8): 'h := java.lang.Integer
Success: build(Test#CacheLoader<? super java.lang.String, java.lang.Integer>) -> Test$Cache<java.lang.String, java.lang.Integer>1 parent 25974fb commit b2bb215
5 files changed
Lines changed: 84 additions & 3 deletions
File tree
- pmd-java/src
- main/java/net/sourceforge/pmd/lang/java
- rule/codestyle
- types/internal/infer
- test
- kotlin/net/sourceforge/pmd/lang/java/types/internal/infer
- resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
| 529 | + | |
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
356 | 396 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
531 | 572 | | |
0 commit comments