Skip to content

Commit d0bf424

Browse files
authored
Merge pull request #9806 from igfoo/igfoo/useType
Kotlin: Extract an ErrorType if we fail to correctly extract a type
2 parents de6a937 + 1bcb17b commit d0bf424

File tree

9 files changed

+4666
-2096
lines changed

9 files changed

+4666
-2096
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,26 @@ open class KotlinUsesExtractor(
111111
}
112112
data class TypeResults(val javaResult: TypeResult<DbType>, val kotlinResult: TypeResult<DbKt_type>)
113113

114-
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER) =
114+
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER): TypeResults {
115115
when(t) {
116-
is IrSimpleType -> useSimpleType(t, context)
116+
is IrSimpleType -> return useSimpleType(t, context)
117117
else -> {
118118
logger.error("Unrecognised IrType: " + t.javaClass)
119-
TypeResults(TypeResult(fakeLabel(), "unknown", "unknown"), TypeResult(fakeLabel(), "unknown", "unknown"))
119+
return extractErrorType()
120120
}
121121
}
122+
}
123+
124+
private fun extractErrorType(): TypeResults {
125+
val typeId = tw.getLabelFor<DbErrortype>("@\"errorType\"") {
126+
tw.writeError_type(it)
127+
}
128+
val kotlinTypeId = tw.getLabelFor<DbKt_nullable_type>("@\"errorKotlinType\"") {
129+
tw.writeKt_nullable_types(it, typeId)
130+
}
131+
return TypeResults(TypeResult(typeId, null, "<CodeQL error type>"),
132+
TypeResult(kotlinTypeId, null, "<CodeQL error type>"))
133+
}
122134

123135
fun getJavaEquivalentClass(c: IrClass) =
124136
getJavaEquivalentClassId(c)?.let { pluginContext.referenceClass(it.asSingleFqName()) }?.owner
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added an `ErrorType` class. An instance of this class will be used if an extractor is unable to extract a type, or if an up/downgrade script is unable to provide a type.

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ modifiers(
332332
string nodeName: string ref
333333
);
334334

335+
/**
336+
* An errortype is used when the extractor is unable to extract a type
337+
* correctly for some reason.
338+
*/
339+
error_type(
340+
unique int id: @errortype
341+
);
342+
335343
classes(
336344
unique int id: @class,
337345
string nodeName: string ref,
@@ -1012,13 +1020,13 @@ javadocText(
10121020
@classorinterfaceorpackage = @classorinterface | @package;
10131021
@classorinterfaceorcallable = @classorinterface | @callable;
10141022
@boundedtype = @typevariable | @wildcard;
1015-
@reftype = @classorinterface | @array | @boundedtype;
1023+
@reftype = @classorinterface | @array | @boundedtype | @errortype;
10161024
@classorarray = @class | @array;
10171025
@type = @primitive | @reftype;
10181026
@callable = @method | @constructor;
10191027

10201028
/** A program element that has a name. */
1021-
@element = @package | @modifier | @annotation |
1029+
@element = @package | @modifier | @annotation | @errortype |
10221030
@locatableElement;
10231031

10241032
@locatableElement = @file | @primitive | @class | @interface | @method | @constructor | @param | @exception | @field |

0 commit comments

Comments
 (0)