Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose simple names on a missing types's synthetic declaration #1232

Open
danysantiago opened this issue Dec 7, 2022 · 1 comment · May be fixed by #1848
Open

Expose simple names on a missing types's synthetic declaration #1232

danysantiago opened this issue Dec 7, 2022 · 1 comment · May be fixed by #1848
Labels
enhancement New feature or request
Milestone

Comments

@danysantiago
Copy link
Member

In javac, an ErrorType is a DeclaredType and one can get an Element out of it. Its simpleName will be the name as it was defined in the sources.

But in KSP, the KSDeclaration of a an error KSType is a synthetic declaration (specifically that KSErrorTypeClassDeclaration singleton) and its simple name is always <Error>.

This would be very helpful for reporting to the user nice traces to the missing type:

package test

import bar.MissingType;

class TestClass {
  fun foo(missing: MissingType) = TODO()
}
Validation trace:
    => element (CLASS): test.TestClass
    => element (METHOD): foo(MissingType)
    => type (EXECUTABLE method): (MissingType)void
    => type (ERROR parameter type): MissingType

Note that if the type is qualified in the source, it will be similarly be reported as its 'simple name' in javac:

 fun foo(missing: bar.MissingType) = TODO()
    => type (ERROR parameter type): bar.MissingType
@kuanyingchou
Copy link
Contributor

kuanyingchou commented Aug 8, 2023

EDIT: Just found that it's already mentioned above. Please ignore this.

Just to add that javac/kapt keeps the original referenced names and not just simple names, for example, with:

class Foo {
    fun barQualified(missing: bar.MissingType) = TODO()
}

We can get "bar.MissingType" in javac/kapt.

@ting-yuan ting-yuan modified the milestones: 1.0.9, 1.0.14 Aug 10, 2023
@ting-yuan ting-yuan modified the milestones: 1.0.14, Dagger Sep 28, 2023
Jeffset added a commit to Jeffset/ksp that referenced this issue Apr 18, 2024
This CL makes `KSErrorType` a class with a string
"hint", that by convention should be a "simpleName"
of an unresolved type.

`KSErrorTypeClassDeclaration` is also no longer a singleton
and references a corresponding `KSErrorType`.

The implementation consists of extracting the available
info on the unresolved type on the best effort basis.
@Jeffset Jeffset linked a pull request Apr 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants