Improved type system
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user