Analyzer does light upward type inference for location expressions

This commit is contained in:
Sasha Koshka 2023-11-29 18:52:27 -05:00
parent 1cd972f50f
commit 19a6b73f0e
2 changed files with 28 additions and 1 deletions

View File

@ -155,6 +155,17 @@ Bird: ([fly distance:F64] [land])
`)
}
func TestAssignmentLiteralErrDerefByteFloat (test *testing.T) {
testStringErr (test,
"cannot use float literal as Byte", 4, 17,
`
[main] = {
buffer:8:Byte
[. buffer 7] = 0.0
}
`)
}
func TestAssignmentLiteral (test *testing.T) {
testString (test,
`
@ -175,6 +186,9 @@ testString (test,
struct:(x:Int y:Int) = (
x: 9
y: 10)
[.[.arr 1] 0] = 6
[.slice 4] = 5
}
`)
}

View File

@ -184,6 +184,13 @@ func (this *Tree) analyzeSubscript (
if err != nil { return nil, err }
subscript.Offset = offset
if subscript.Ty == nil {
switch ty := subscript.Slice.Type().(type) {
case *entity.TypeSlice: subscript.Ty = ty.Element
case *entity.TypeArray: subscript.Ty = ty.Element
}
}
return subscript, nil
}
@ -235,7 +242,13 @@ func (this *Tree) analyzeDereference (
if err != nil { return nil, err }
dereference.Pointer = pointer
dereference.Ty = into
if dereference.Ty == nil {
switch ty := dereference.Pointer.Type().(type) {
case *entity.TypePointer: dereference.Ty = ty.Referenced
}
}
return dereference, nil
}