shortenFullyQualifiedTypes can change type resolution for inherited nested types
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 52/100
Direção de pesquisa
Start with the shortenFullyQualifiedTypes() implementation and reproduce the issue using the linked Gradle project and ./gradlew spotlessApply. Trace how inherited nested types affect shortening decisions, then verify that the qualified external.Type reference remains safe and the formatted project still compiles.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
shortenFullyQualifiedTypes can change the meaning of a qualified type when the simple name is also an inherited nested type.
The formatter avoids some collisions with types declared in the same compilation unit, but does not appear to account for member types inherited from a superclass or interface.
Reproducer
Spotless Gradle plugin 8.10.3, with shortenFullyQualifiedTypes() as the only configured Java step:
The complete Gradle project is available here:
https://gist.github.com/MattAlp/a50100bc9d712c470ded424c36e8f315
The reproducer contains:
Base, which declares nested typeTypeChild, which extendsBaseexternal.Type, which is referenced by fully qualified name
Before formatting, Child contains:
public static String use(external.Type value) {
return value.externalOnly();
}
The project compiles successfully. After running:
./gradlew spotlessApply
Spotless adds import external.Type; and changes the code to:
public static String use(Type value) {
return value.externalOnly();
}
The unqualified Type resolves to the inherited Base.Type, not external.Type. Compilation then fails:
cannot find symbol
method externalOnly()
location: variable value of type Type
Suggested behavior
Leave a qualified reference alone when its simple name can resolve to an inherited member type. If this cannot be determined without a classpath, the conservative behavior should be to leave the qualification intact.
Related work
This appears related to:
- #3033 — same-compilation-unit type collisions
- #3031 — collisions with types declared in the same file
- #3037 — preserving existing unqualified type resolution
- Linguagem predominante
- Java
- Estrelas
- 5.7k
- Forks
- 562
- Merge médio
- 3d 2h
- PRs com merge (30d)
- 30
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de diffplug/spotless
-
Expose `maxLineLength` on the `googleJavaFormat` step (configurable upstream since gjf 1.37.0)Talvez já em andamento @xzxiaoshan assumiu há 2 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 28/100
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 43/100
diffplug/spotless#3147 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 28/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
Mantenedores costumam responder em até 1 dia
Todas as issues de diffplug/spotless
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
code-maintenance
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
krizaka/krizaka-notifications#32 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
klikli-dev/occultism#1719 ·