Skip to content

Commit

Permalink
Adding unsafe types to Go
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Sep 29, 2023
1 parent 51c82f0 commit a7fb181
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ class GoLanguage :
// TODO: Actually, this should be a type alias to uint8
"byte" to IntegerType("uint8", 8, this, NumericType.Modifier.UNSIGNED),
// https://pkg.go.dev/builtin#string
"string" to StringType("string", this)
"string" to StringType("string", this),
// https://go.dev/ref/spec#Package_unsafe
"unsafe.ArbitraryType" to ObjectType("unsafe.ArbitraryType", listOf(), false, this),
// https://go.dev/ref/spec#Package_unsafe
"unsafe.IntegerType" to ObjectType("unsafe.IntegerType", listOf(), false, this)
)

override fun isDerivedFrom(
Expand All @@ -120,7 +124,20 @@ class GoLanguage :
hint: HasType?,
superHint: HasType?
): Boolean {
if (type == superType || superType == primitiveType("any")) {
if (
type == superType ||
// "any" accepts any type
superType == primitiveType("any") ||
// the unsafe.ArbitraryType is a fake type in the unsafe package, that also accepts
// any type
superType == primitiveType("unsafe.ArbitraryType")
) {
return true
}

// the unsafe.IntegerType is a fake type in the unsafe package, that accepts any integer
// type
if (type is IntegerType && superType == primitiveType("unsafe.IntegerType")) {
return true
}

Expand Down

0 comments on commit a7fb181

Please sign in to comment.