Skip to content

Commit ad7b725

Browse files
committed
add unsafe extension function for casting between composite types and aggregate types
1 parent 1d26c33 commit ad7b725

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

type-system/src/commonMain/kotlin/io/github/charlietap/chasm/type/ext/CompositeTypeExt.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import io.github.charlietap.chasm.type.CompositeType
55
import io.github.charlietap.chasm.type.FunctionType
66
import io.github.charlietap.chasm.type.StructType
77

8+
inline fun CompositeType.arrayType(): ArrayType? {
9+
return (this as? CompositeType.Array)?.arrayType
10+
}
11+
812
inline fun CompositeType.functionType(): FunctionType? {
913
return (this as? CompositeType.Function)?.functionType
1014
}
@@ -13,6 +17,14 @@ inline fun CompositeType.structType(): StructType? {
1317
return (this as? CompositeType.Struct)?.structType
1418
}
1519

16-
inline fun CompositeType.arrayType(): ArrayType? {
17-
return (this as? CompositeType.Array)?.arrayType
20+
inline fun CompositeType.asArrayType(): ArrayType {
21+
return (this as CompositeType.Array).arrayType
22+
}
23+
24+
inline fun CompositeType.asFunctionType(): FunctionType {
25+
return (this as CompositeType.Function).functionType
26+
}
27+
28+
inline fun CompositeType.asStructType(): StructType {
29+
return (this as CompositeType.Struct).structType
1830
}

0 commit comments

Comments
 (0)