[FIR2IR] Replace 'throw AssertionError()' with error() / assert() {...}
This commit is contained in:
+2
-2
@@ -80,11 +80,11 @@ open class FirJvmMangleComputer(
|
|||||||
}
|
}
|
||||||
if (parentClassId != null && !parentClassId.isLocal) {
|
if (parentClassId != null && !parentClassId.isLocal) {
|
||||||
val parentClassLike = session.firSymbolProvider.getClassLikeSymbolByFqName(parentClassId)?.fir
|
val parentClassLike = session.firSymbolProvider.getClassLikeSymbolByFqName(parentClassId)?.fir
|
||||||
?: throw AssertionError("Attempt to find parent ($parentClassId) for probably-local declaration!")
|
?: error("Attempt to find parent ($parentClassId) for probably-local declaration!")
|
||||||
if (parentClassLike is FirRegularClass || parentClassLike is FirTypeAlias) {
|
if (parentClassLike is FirRegularClass || parentClassLike is FirTypeAlias) {
|
||||||
parentClassLike.accept(this@FirJvmMangleComputer, false)
|
parentClassLike.accept(this@FirJvmMangleComputer, false)
|
||||||
} else {
|
} else {
|
||||||
throw AssertionError("Strange class-like declaration: ${parentClassLike.render()}")
|
error("Strange class-like declaration: ${parentClassLike.render()}")
|
||||||
}
|
}
|
||||||
} else if (parentClassId == null && !parentPackageFqName.isRoot) {
|
} else if (parentClassId == null && !parentPackageFqName.isRoot) {
|
||||||
builder.appendName(parentPackageFqName.asString())
|
builder.appendName(parentPackageFqName.asString())
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ fun FirClassifierSymbol<*>.toSymbol(
|
|||||||
is FirClassSymbol -> {
|
is FirClassSymbol -> {
|
||||||
classifierStorage.getIrClassSymbol(this)
|
classifierStorage.getIrClassSymbol(this)
|
||||||
}
|
}
|
||||||
else -> throw AssertionError("Should not be here: $this")
|
else -> error("Unknown symbol: $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ fun FirReference.toSymbol(
|
|||||||
resolvedSymbol.toSymbol(session, classifierStorage)
|
resolvedSymbol.toSymbol(session, classifierStorage)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
throw AssertionError("Unknown symbol: $resolvedSymbol")
|
error("Unknown symbol: $resolvedSymbol")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -451,6 +451,6 @@ class Fir2IrClassifierStorage(
|
|||||||
typeContext: ConversionTypeContext
|
typeContext: ConversionTypeContext
|
||||||
): IrTypeParameterSymbol {
|
): IrTypeParameterSymbol {
|
||||||
return getCachedIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)?.symbol
|
return getCachedIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)?.symbol
|
||||||
?: throw AssertionError("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
|
?: error("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ class Fir2IrConverter(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
throw AssertionError("Unexpected member: ${declaration::class}")
|
error("Unexpected member: ${declaration::class}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-10
@@ -201,7 +201,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
val containerFile = when (firBasedSymbol) {
|
val containerFile = when (firBasedSymbol) {
|
||||||
is FirCallableSymbol -> firProvider.getFirCallableContainerFile(firBasedSymbol)
|
is FirCallableSymbol -> firProvider.getFirCallableContainerFile(firBasedSymbol)
|
||||||
is FirClassLikeSymbol -> firProvider.getFirClassifierContainerFileIfAny(firBasedSymbol)
|
is FirClassLikeSymbol -> firProvider.getFirClassifierContainerFileIfAny(firBasedSymbol)
|
||||||
else -> throw AssertionError("Unexpected: $firBasedSymbol")
|
else -> error("Unknown symbol: $firBasedSymbol")
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
when {
|
||||||
@@ -302,8 +302,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
if (function !is FirAnonymousFunction && containingClass != null && !isStatic) {
|
if (function !is FirAnonymousFunction && containingClass != null && !isStatic) {
|
||||||
dispatchReceiverParameter = declareThisReceiverParameter(
|
dispatchReceiverParameter = declareThisReceiverParameter(
|
||||||
symbolTable,
|
symbolTable,
|
||||||
thisType = containingClass.thisReceiver?.type
|
thisType = containingClass.thisReceiver?.type ?: error("No this receiver"),
|
||||||
?: throw AssertionError(),
|
|
||||||
thisOrigin = thisOrigin
|
thisOrigin = thisOrigin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -831,8 +830,8 @@ class Fir2IrDeclarationStorage(
|
|||||||
constructorCache[firConstructor] = irFunction
|
constructorCache[firConstructor] = irFunction
|
||||||
return irConstructorSymbol
|
return irConstructorSymbol
|
||||||
}
|
}
|
||||||
if (parentOrigin == IrDeclarationOrigin.DEFINED) {
|
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
||||||
throw AssertionError()
|
"Should not have reference to public API uncached constructor from source code"
|
||||||
}
|
}
|
||||||
val symbol = Fir2IrConstructorSymbol(signature)
|
val symbol = Fir2IrConstructorSymbol(signature)
|
||||||
val irConstructor = firConstructor.convertWithOffsets { startOffset, endOffset ->
|
val irConstructor = firConstructor.convertWithOffsets { startOffset, endOffset ->
|
||||||
@@ -870,8 +869,8 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
// TODO: package fragment members (?)
|
// TODO: package fragment members (?)
|
||||||
if (firDeclaration is FirSimpleFunction && irParent is Fir2IrLazyClass) {
|
if (firDeclaration is FirSimpleFunction && irParent is Fir2IrLazyClass) {
|
||||||
if (parentOrigin == IrDeclarationOrigin.DEFINED) {
|
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
||||||
throw AssertionError()
|
"Should not have reference to public API uncached simple function from source code"
|
||||||
}
|
}
|
||||||
val symbol = Fir2IrSimpleFunctionSymbol(signature, firDeclaration.containerSource)
|
val symbol = Fir2IrSimpleFunctionSymbol(signature, firDeclaration.containerSource)
|
||||||
val irFunction = firDeclaration.convertWithOffsets { startOffset, endOffset ->
|
val irFunction = firDeclaration.convertWithOffsets { startOffset, endOffset ->
|
||||||
@@ -899,7 +898,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
is FirConstructor -> {
|
is FirConstructor -> {
|
||||||
getIrConstructorSymbol(firDeclaration.symbol)
|
getIrConstructorSymbol(firDeclaration.symbol)
|
||||||
}
|
}
|
||||||
else -> throw AssertionError("Should not be here: ${firDeclaration::class.java}: ${firDeclaration.render()}")
|
else -> error("Unknown kind of function: ${firDeclaration::class.java}: ${firDeclaration.render()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -918,8 +917,8 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
// TODO: package fragment members (?)
|
// TODO: package fragment members (?)
|
||||||
if (irParent is Fir2IrLazyClass) {
|
if (irParent is Fir2IrLazyClass) {
|
||||||
if (parentOrigin == IrDeclarationOrigin.DEFINED) {
|
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
|
||||||
throw AssertionError()
|
"Should not have reference to public API uncached property from source code"
|
||||||
}
|
}
|
||||||
val symbol = Fir2IrPropertySymbol(signature, fir.containerSource)
|
val symbol = Fir2IrPropertySymbol(signature, fir.containerSource)
|
||||||
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
|
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
|
||||||
|
|||||||
@@ -124,8 +124,7 @@ class Fir2IrTypeConverter(
|
|||||||
private fun getArrayClassSymbol(classId: ClassId?): IrClassSymbol? {
|
private fun getArrayClassSymbol(classId: ClassId?): IrClassSymbol? {
|
||||||
val primitiveId = StandardClassIds.elementTypeByPrimitiveArrayType[classId] ?: return null
|
val primitiveId = StandardClassIds.elementTypeByPrimitiveArrayType[classId] ?: return null
|
||||||
val irType = classIdToTypeMap[primitiveId]
|
val irType = classIdToTypeMap[primitiveId]
|
||||||
return irBuiltIns.primitiveArrayForType[irType]
|
return irBuiltIns.primitiveArrayForType[irType] ?: error("Strange primitiveId $primitiveId from array: $classId")
|
||||||
?: throw AssertionError("Strange primitiveId $primitiveId from array: $classId")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBuiltInClassSymbol(classId: ClassId?): IrClassSymbol? {
|
private fun getBuiltInClassSymbol(classId: ClassId?): IrClassSymbol? {
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class Fir2IrVisitor(
|
|||||||
when (irTarget) {
|
when (irTarget) {
|
||||||
is IrConstructor -> irTarget.symbol
|
is IrConstructor -> irTarget.symbol
|
||||||
is IrSimpleFunction -> irTarget.symbol
|
is IrSimpleFunction -> irTarget.symbol
|
||||||
else -> throw AssertionError("Should not be here: $irTarget")
|
else -> error("Unknown return target: $irTarget")
|
||||||
},
|
},
|
||||||
convertToIrExpression(result)
|
convertToIrExpression(result)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ private fun leastCommonPrimitiveNumericType(t1: ConeClassLikeType, t2: ConeClass
|
|||||||
pt1.isFloat() || pt2.isFloat() -> PrimitiveTypes.Float
|
pt1.isFloat() || pt2.isFloat() -> PrimitiveTypes.Float
|
||||||
pt1.isLong() || pt2.isLong() -> PrimitiveTypes.Long
|
pt1.isLong() || pt2.isLong() -> PrimitiveTypes.Long
|
||||||
pt1.isInt() || pt2.isInt() -> PrimitiveTypes.Int
|
pt1.isInt() || pt2.isInt() -> PrimitiveTypes.Int
|
||||||
else -> throw AssertionError("Unexpected types: t1=$t1, t2=$t2")
|
else -> error("Unexpected types: t1=$t1, t2=$t2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ private fun ConeClassLikeType.promoteIntegerTypeToIntIfRequired(): ConeClassLike
|
|||||||
when (lookupTag.classId) {
|
when (lookupTag.classId) {
|
||||||
StandardClassIds.Byte, StandardClassIds.Short -> PrimitiveTypes.Int
|
StandardClassIds.Byte, StandardClassIds.Short -> PrimitiveTypes.Int
|
||||||
StandardClassIds.Long, StandardClassIds.Int, StandardClassIds.Float, StandardClassIds.Double, StandardClassIds.Char -> this
|
StandardClassIds.Long, StandardClassIds.Int, StandardClassIds.Float, StandardClassIds.Double, StandardClassIds.Char -> this
|
||||||
else -> throw AssertionError("Primitive number type expected: $this")
|
else -> error("Primitive number type expected: $this")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConeKotlinType.getPrimitiveTypeOrSupertype(): ConeClassLikeType? =
|
private fun ConeKotlinType.getPrimitiveTypeOrSupertype(): ConeClassLikeType? =
|
||||||
|
|||||||
+1
-3
@@ -485,9 +485,7 @@ class CallAndReferenceGenerator(
|
|||||||
?: run {
|
?: run {
|
||||||
if (this is FirCallableReferenceAccess) return null
|
if (this is FirCallableReferenceAccess) return null
|
||||||
val name = if (isDispatch) "Dispatch" else "Extension"
|
val name = if (isDispatch) "Dispatch" else "Extension"
|
||||||
throw AssertionError(
|
error("$name receiver expected: ${render()} to ${calleeReference.render()}")
|
||||||
"$name receiver expected: ${render()} to ${calleeReference.render()}"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -250,7 +250,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
components.irBuiltIns.booleanType -> FirImplicitBooleanTypeRef(null)
|
components.irBuiltIns.booleanType -> FirImplicitBooleanTypeRef(null)
|
||||||
components.irBuiltIns.intType -> FirImplicitIntTypeRef(null)
|
components.irBuiltIns.intType -> FirImplicitIntTypeRef(null)
|
||||||
components.irBuiltIns.stringType -> FirImplicitStringTypeRef(null)
|
components.irBuiltIns.stringType -> FirImplicitStringTypeRef(null)
|
||||||
else -> throw AssertionError("Should not be here")
|
else -> error("Unexpected synthetic data class function return type: $returnType")
|
||||||
}
|
}
|
||||||
if (irValueParameter != null) {
|
if (irValueParameter != null) {
|
||||||
this.valueParameters.add(
|
this.valueParameters.add(
|
||||||
|
|||||||
+2
-2
@@ -145,14 +145,14 @@ internal class OperatorExpressionGenerator(
|
|||||||
targetType: ConeClassLikeType?
|
targetType: ConeClassLikeType?
|
||||||
): IrExpression {
|
): IrExpression {
|
||||||
if (targetType == null) return this
|
if (targetType == null) return this
|
||||||
if (operandType == null) throw AssertionError("operandType should be non-null")
|
if (operandType == null) error("operandType should be non-null if targetType is non-null")
|
||||||
|
|
||||||
val operandClassId = operandType.lookupTag.classId
|
val operandClassId = operandType.lookupTag.classId
|
||||||
val targetClassId = targetType.lookupTag.classId
|
val targetClassId = targetType.lookupTag.classId
|
||||||
if (operandClassId == targetClassId) return this
|
if (operandClassId == targetClassId) return this
|
||||||
val conversionFunction =
|
val conversionFunction =
|
||||||
typeConverter.classIdToSymbolMap[operandClassId]?.getSimpleFunction("to${targetType.lookupTag.classId.shortClassName.asString()}")
|
typeConverter.classIdToSymbolMap[operandClassId]?.getSimpleFunction("to${targetType.lookupTag.classId.shortClassName.asString()}")
|
||||||
?: throw AssertionError("No conversion function for $operandType ~> $targetType")
|
?: error("No conversion function for $operandType ~> $targetType")
|
||||||
|
|
||||||
val dispatchReceiver = this@asComparisonOperand
|
val dispatchReceiver = this@asComparisonOperand
|
||||||
val unsafeIrCall = IrCallImpl(
|
val unsafeIrCall = IrCallImpl(
|
||||||
|
|||||||
@@ -56,19 +56,19 @@ class Fir2IrLazyClass(
|
|||||||
override var visibility: Visibility
|
override var visibility: Visibility
|
||||||
get() = fir.visibility
|
get() = fir.visibility
|
||||||
set(_) {
|
set(_) {
|
||||||
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
|
error("Mutating Fir2Ir lazy elements is not possible")
|
||||||
}
|
}
|
||||||
|
|
||||||
override var modality: Modality
|
override var modality: Modality
|
||||||
get() = fir.modality!!
|
get() = fir.modality!!
|
||||||
set(_) {
|
set(_) {
|
||||||
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
|
error("Mutating Fir2Ir lazy elements is not possible")
|
||||||
}
|
}
|
||||||
|
|
||||||
override var attributeOwnerId: IrAttributeContainer
|
override var attributeOwnerId: IrAttributeContainer
|
||||||
get() = this
|
get() = this
|
||||||
set(_) {
|
set(_) {
|
||||||
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
|
error("Mutating Fir2Ir lazy elements is not possible")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val kind: ClassKind
|
override val kind: ClassKind
|
||||||
@@ -160,9 +160,10 @@ class Fir2IrLazyClass(
|
|||||||
with(fakeOverrideGenerator) {
|
with(fakeOverrideGenerator) {
|
||||||
result += getFakeOverrides(fir, processedNames)
|
result += getFakeOverrides(fir, processedNames)
|
||||||
}
|
}
|
||||||
|
// TODO: remove this check to save time
|
||||||
for (declaration in result) {
|
for (declaration in result) {
|
||||||
if (declaration.parent != this) {
|
if (declaration.parent != this) {
|
||||||
throw AssertionError()
|
throw AssertionError("Unmatched parent for lazy class member")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class Fir2IrLazyConstructor(
|
|||||||
override var visibility: Visibility
|
override var visibility: Visibility
|
||||||
get() = fir.visibility
|
get() = fir.visibility
|
||||||
set(_) {
|
set(_) {
|
||||||
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
|
error("Mutating Fir2Ir lazy elements is not possible")
|
||||||
}
|
}
|
||||||
|
|
||||||
override var returnType: IrType by lazyVar {
|
override var returnType: IrType by lazyVar {
|
||||||
@@ -93,7 +93,7 @@ class Fir2IrLazyConstructor(
|
|||||||
override var extensionReceiverParameter: IrValueParameter?
|
override var extensionReceiverParameter: IrValueParameter?
|
||||||
get() = null
|
get() = null
|
||||||
set(_) {
|
set(_) {
|
||||||
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
|
error("Mutating Fir2Ir lazy elements is not possible")
|
||||||
}
|
}
|
||||||
|
|
||||||
override var valueParameters: List<IrValueParameter> by lazyVar {
|
override var valueParameters: List<IrValueParameter> by lazyVar {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class Fir2IrLazyProperty(
|
|||||||
override var visibility: Visibility
|
override var visibility: Visibility
|
||||||
get() = fir.visibility
|
get() = fir.visibility
|
||||||
set(_) {
|
set(_) {
|
||||||
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
|
error("Mutating Fir2Ir lazy elements is not possible")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val modality: Modality
|
override val modality: Modality
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ class Fir2IrLazySimpleFunction(
|
|||||||
declarationStorage.enterScope(this)
|
declarationStorage.enterScope(this)
|
||||||
declareThisReceiverParameter(
|
declareThisReceiverParameter(
|
||||||
symbolTable,
|
symbolTable,
|
||||||
thisType = containingClass.thisReceiver?.type
|
thisType = containingClass.thisReceiver?.type ?: error("No this receiver for containing class"),
|
||||||
?: throw AssertionError(),
|
|
||||||
thisOrigin = origin
|
thisOrigin = origin
|
||||||
).apply {
|
).apply {
|
||||||
declarationStorage.leaveScope(this@Fir2IrLazySimpleFunction)
|
declarationStorage.leaveScope(this@Fir2IrLazySimpleFunction)
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
|
|||||||
callableId.packageName.asString(), callableId.relativeCallableName.asString(), builder.hashId, builder.mask
|
callableId.packageName.asString(), callableId.relativeCallableName.asString(), builder.hashId, builder.mask
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> throw AssertionError("Unsupported FIR declaration in signature composer: ${declaration.render()}")
|
else -> error("Unsupported FIR declaration in signature composer: ${declaration.render()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user