-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow KSErrorType to receive a message as additional piece of information on why a valid type can't be provided. Cover `replace`/`asType` cases with a utility function `errorTypeOnInconsistentArguments` to get consistent error messages across implementations. Tweak KSTypeImpl.isError detection in AA, move TODO there. (cherry picked from commit 319ddff)
- Loading branch information
Showing
19 changed files
with
207 additions
and
190 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
common-util/src/main/kotlin/com/google/devtools/ksp/common/ErrorTypeUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.google.devtools.ksp.common | ||
|
||
import com.google.devtools.ksp.symbol.KSType | ||
import com.google.devtools.ksp.symbol.KSTypeArgument | ||
|
||
inline fun <E> errorTypeOnInconsistentArguments( | ||
arguments: List<KSTypeArgument>, | ||
placeholdersProvider: () -> List<KSTypeArgument>, | ||
withCorrectedArguments: (corrected: List<KSTypeArgument>) -> KSType, | ||
errorType: (name: String, message: String) -> E, | ||
): E? { | ||
if (arguments.isNotEmpty()) { | ||
val placeholders = placeholdersProvider() | ||
val diff = arguments.size - placeholders.size | ||
if (diff > 0) { | ||
val wouldBeType = withCorrectedArguments(arguments.dropLast(diff)) | ||
return errorType(wouldBeType.toString(), "Unexpected extra $diff type argument(s)") | ||
} else if (diff < 0) { | ||
val wouldBeType = withCorrectedArguments(arguments + placeholders.drop(arguments.size)) | ||
return errorType(wouldBeType.toString(), "Missing ${-diff} type argument(s)") | ||
} | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.