mirror of
https://github.com/github/codeql.git
synced 2025-12-24 20:56:33 +01:00
Kotlin: Extract an ErrorType if we fail to correctly extract a type
This commit is contained in:
@@ -108,14 +108,26 @@ open class KotlinUsesExtractor(
|
|||||||
}
|
}
|
||||||
data class TypeResults(val javaResult: TypeResult<DbType>, val kotlinResult: TypeResult<DbKt_type>)
|
data class TypeResults(val javaResult: TypeResult<DbType>, val kotlinResult: TypeResult<DbKt_type>)
|
||||||
|
|
||||||
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER) =
|
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER): TypeResults {
|
||||||
when(t) {
|
when(t) {
|
||||||
is IrSimpleType -> useSimpleType(t, context)
|
is IrSimpleType -> return useSimpleType(t, context)
|
||||||
else -> {
|
else -> {
|
||||||
logger.error("Unrecognised IrType: " + t.javaClass)
|
logger.error("Unrecognised IrType: " + t.javaClass)
|
||||||
TypeResults(TypeResult(fakeLabel(), "unknown", "unknown"), TypeResult(fakeLabel(), "unknown", "unknown"))
|
return extractErrorType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun extractErrorType(): TypeResults {
|
||||||
|
val typeId = tw.getLabelFor<DbErrortype>("@\"errorType\"") {
|
||||||
|
tw.writeError_type(it)
|
||||||
|
}
|
||||||
|
val kotlinTypeId = tw.getLabelFor<DbKt_nullable_type>("@\"errorKotlinType\"") {
|
||||||
|
tw.writeKt_nullable_types(it, typeId)
|
||||||
|
}
|
||||||
|
return TypeResults(TypeResult(typeId, null, "<CodeQL error type>"),
|
||||||
|
TypeResult(kotlinTypeId, null, "<CodeQL error type>"))
|
||||||
|
}
|
||||||
|
|
||||||
fun getJavaEquivalentClass(c: IrClass) =
|
fun getJavaEquivalentClass(c: IrClass) =
|
||||||
getJavaEquivalentClassId(c)?.let { pluginContext.referenceClass(it.asSingleFqName()) }?.owner
|
getJavaEquivalentClassId(c)?.let { pluginContext.referenceClass(it.asSingleFqName()) }?.owner
|
||||||
|
|||||||
@@ -332,6 +332,14 @@ modifiers(
|
|||||||
string nodeName: string ref
|
string nodeName: string ref
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An errortype is used when the extractor is unable to extract a type
|
||||||
|
* correctly for some reason.
|
||||||
|
*/
|
||||||
|
error_type(
|
||||||
|
unique int id: @errortype
|
||||||
|
);
|
||||||
|
|
||||||
classes(
|
classes(
|
||||||
unique int id: @class,
|
unique int id: @class,
|
||||||
string nodeName: string ref,
|
string nodeName: string ref,
|
||||||
@@ -1012,13 +1020,13 @@ javadocText(
|
|||||||
@classorinterfaceorpackage = @classorinterface | @package;
|
@classorinterfaceorpackage = @classorinterface | @package;
|
||||||
@classorinterfaceorcallable = @classorinterface | @callable;
|
@classorinterfaceorcallable = @classorinterface | @callable;
|
||||||
@boundedtype = @typevariable | @wildcard;
|
@boundedtype = @typevariable | @wildcard;
|
||||||
@reftype = @classorinterface | @array | @boundedtype;
|
@reftype = @classorinterface | @array | @boundedtype | @errortype;
|
||||||
@classorarray = @class | @array;
|
@classorarray = @class | @array;
|
||||||
@type = @primitive | @reftype;
|
@type = @primitive | @reftype;
|
||||||
@callable = @method | @constructor;
|
@callable = @method | @constructor;
|
||||||
|
|
||||||
/** A program element that has a name. */
|
/** A program element that has a name. */
|
||||||
@element = @package | @modifier | @annotation |
|
@element = @package | @modifier | @annotation | @errortype |
|
||||||
@locatableElement;
|
@locatableElement;
|
||||||
|
|
||||||
@locatableElement = @file | @primitive | @class | @interface | @method | @constructor | @param | @exception | @field |
|
@locatableElement = @file | @primitive | @class | @interface | @method | @constructor | @param | @exception | @field |
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ predicate hasName(Element e, string name) {
|
|||||||
kt_type_alias(e, name, _)
|
kt_type_alias(e, name, _)
|
||||||
or
|
or
|
||||||
ktProperties(e, name)
|
ktProperties(e, name)
|
||||||
|
or
|
||||||
|
e instanceof ErrorType and name = "<CodeQL error type>"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -666,6 +666,14 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An `ErrorType` is generated when CodeQL is unable to correctly
|
||||||
|
* extract a type.
|
||||||
|
*/
|
||||||
|
class ErrorType extends RefType, @errortype {
|
||||||
|
override string getAPrimaryQlClass() { result = "ErrorType" }
|
||||||
|
}
|
||||||
|
|
||||||
/** A type that is the same as its source declaration. */
|
/** A type that is the same as its source declaration. */
|
||||||
class SrcRefType extends RefType {
|
class SrcRefType extends RefType {
|
||||||
SrcRefType() { this.isSourceDeclaration() }
|
SrcRefType() { this.isSourceDeclaration() }
|
||||||
|
|||||||
Reference in New Issue
Block a user