@@ -25,7 +25,9 @@ import org.jetbrains.kotlin.fir.symbols.SymbolInternals
25
25
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
26
26
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
27
27
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
28
+ import org.jetbrains.kotlin.fir.types.ConeFlexibleType
28
29
import org.jetbrains.kotlin.fir.types.ConeKotlinType
30
+ import org.jetbrains.kotlin.fir.types.ConeNullability
29
31
import org.jetbrains.kotlin.fir.types.ConeStarProjection
30
32
import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
31
33
import org.jetbrains.kotlin.fir.types.canBeNull
@@ -41,15 +43,19 @@ import org.jetbrains.kotlin.fir.types.resolvedType
41
43
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
42
44
import org.jetbrains.kotlin.fir.types.toSymbol
43
45
import org.jetbrains.kotlin.fir.types.type
46
+ import org.jetbrains.kotlin.fir.types.typeContext
44
47
import org.jetbrains.kotlin.fir.types.upperBoundIfFlexible
45
48
import org.jetbrains.kotlin.fir.types.withArguments
49
+ import org.jetbrains.kotlin.fir.types.withNullability
46
50
import org.jetbrains.kotlin.name.ClassId
47
51
import org.jetbrains.kotlin.name.FqName
48
52
import org.jetbrains.kotlin.name.Name
49
53
import org.jetbrains.kotlin.name.StandardClassIds
50
54
import org.jetbrains.kotlin.name.StandardClassIds.List
55
+ import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.withNullability
51
56
import org.jetbrains.kotlinx.dataframe.codeGen.*
52
57
import org.jetbrains.kotlinx.dataframe.plugin.extensions.KotlinTypeFacade
58
+ import org.jetbrains.kotlinx.dataframe.plugin.extensions.wrap
53
59
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractInterpreter
54
60
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractSchemaModificationInterpreter
55
61
import org.jetbrains.kotlinx.dataframe.plugin.impl.Arguments
@@ -197,7 +203,7 @@ internal fun KotlinTypeFacade.toDataFrame(
197
203
val preserveClasses = traverseConfiguration.preserveClasses.mapNotNullTo(mutableSetOf ()) { it.classId }
198
204
val preserveProperties = traverseConfiguration.preserveProperties.mapNotNullTo(mutableSetOf ()) { it.calleeReference.toResolvedPropertySymbol() }
199
205
200
- fun convert (classLike : ConeKotlinType , depth : Int ): List <SimpleCol > {
206
+ fun convert (classLike : ConeKotlinType , depth : Int , makeNullable : Boolean ): List <SimpleCol > {
201
207
val symbol = classLike.toRegularClassSymbol(session) ? : return emptyList()
202
208
val scope = symbol.unsubstitutedScope(session, ScopeSession (), false , FirResolvePhase .STATUS )
203
209
val declarations = if (symbol.fir is FirJavaClass ) {
@@ -260,7 +266,7 @@ internal fun KotlinTypeFacade.toDataFrame(
260
266
261
267
val keepSubtree = depth >= maxDepth && ! fieldKind.shouldBeConvertedToColumnGroup && ! fieldKind.shouldBeConvertedToFrameColumn
262
268
if (keepSubtree || returnType.isValueType() || returnType.classId in preserveClasses || it in preserveProperties) {
263
- SimpleDataColumn (name, TypeApproximation (returnType))
269
+ SimpleDataColumn (name, TypeApproximation (returnType.withNullability( ConeNullability .create(makeNullable), session.typeContext) ))
264
270
} else if (
265
271
returnType.isSubtypeOf(StandardClassIds .Iterable .constructClassLikeType(arrayOf(ConeStarProjection )), session) ||
266
272
returnType.isSubtypeOf(StandardClassIds .Iterable .constructClassLikeType(arrayOf(ConeStarProjection ), isNullable = true ), session)
@@ -271,19 +277,15 @@ internal fun KotlinTypeFacade.toDataFrame(
271
277
else -> session.builtinTypes.nullableAnyType.type
272
278
}
273
279
if (type.isValueType()) {
274
- SimpleDataColumn (name,
275
- TypeApproximation (
276
- List .constructClassLikeType(
277
- arrayOf(type),
278
- returnType.isNullable
279
- )
280
- )
281
- )
280
+ val columnType = List .constructClassLikeType(arrayOf(type), returnType.isNullable)
281
+ .withNullability(ConeNullability .create(makeNullable), session.typeContext)
282
+ .wrap()
283
+ SimpleDataColumn (name, columnType)
282
284
} else {
283
- SimpleFrameColumn (name, convert(type, depth + 1 ))
285
+ SimpleFrameColumn (name, convert(type, depth + 1 , makeNullable = false ))
284
286
}
285
287
} else {
286
- SimpleColumnGroup (name, convert(returnType, depth + 1 ))
288
+ SimpleColumnGroup (name, convert(returnType, depth + 1 , returnType.isNullable || makeNullable ))
287
289
}
288
290
}
289
291
}
@@ -293,8 +295,12 @@ internal fun KotlinTypeFacade.toDataFrame(
293
295
return when {
294
296
arg.isStarProjection -> PluginDataFrameSchema .EMPTY
295
297
else -> {
296
- val classLike = arg.type as ? ConeClassLikeType ? : return PluginDataFrameSchema .EMPTY
297
- val columns = convert(classLike, 0 )
298
+ val classLike = when (val type = arg.type) {
299
+ is ConeClassLikeType -> type
300
+ is ConeFlexibleType -> type.upperBound
301
+ else -> null
302
+ } ? : return PluginDataFrameSchema .EMPTY
303
+ val columns = convert(classLike, 0 , makeNullable = classLike.isNullable)
298
304
PluginDataFrameSchema (columns)
299
305
}
300
306
}
0 commit comments