Improved type system

This commit is contained in:
2025-02-09 23:52:07 +01:00
parent 7634244c56
commit f19d9063a5
30 changed files with 132 additions and 85 deletions

View File

@ -2,30 +2,26 @@ package types
// Is returns true if the encountered type `a` can be converted into the expected type `b`.
func Is(a Type, b Type) bool {
if a == nil {
return true
}
if a == b {
if a == b || b == Any || a == nil {
return true
}
aPointer, aIsPointer := a.(*Pointer)
bPointer, bIsPointer := b.(*Pointer)
if aIsPointer && bIsPointer && (bPointer.To == nil || aPointer.To == bPointer.To) {
if aIsPointer && bIsPointer && (bPointer.To == Any || aPointer.To == bPointer.To) {
return true
}
aArray, aIsArray := a.(*Array)
if aIsArray && bIsPointer && (bPointer.To == nil || aArray.Of == bPointer.To) {
if aIsArray && bIsPointer && (bPointer.To == Any || aArray.Of == bPointer.To) {
return true
}
bArray, bIsArray := b.(*Array)
if aIsArray && bIsArray && aArray.Of == bArray.Of {
if aIsArray && bIsArray && (bArray.Of == Any || aArray.Of == bArray.Of) {
return true
}