Pass all literal assignment tests
This commit is contained in:
parent
b839517e9a
commit
1a09e9ba2a
@ -113,7 +113,7 @@ testStringErr (test,
|
|||||||
|
|
||||||
func TestAssignmentLiteralErrInterfaceInt (test *testing.T) {
|
func TestAssignmentLiteralErrInterfaceInt (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"cannot use float literal as Bird", 6, 2,
|
"cannot use integer literal as Bird", 4, 11,
|
||||||
`
|
`
|
||||||
Bird: ([fly distance:F64] [land])
|
Bird: ([fly distance:F64] [land])
|
||||||
[main] = {
|
[main] = {
|
||||||
@ -124,7 +124,7 @@ Bird: ([fly distance:F64] [land])
|
|||||||
|
|
||||||
func TestAssignmentLiteralErrInterfaceFloat (test *testing.T) {
|
func TestAssignmentLiteralErrInterfaceFloat (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"cannot use integer literal as Bird", 6, 2,
|
"cannot use float literal as Bird", 4, 11,
|
||||||
`
|
`
|
||||||
Bird: ([fly distance:F64] [land])
|
Bird: ([fly distance:F64] [land])
|
||||||
[main] = {
|
[main] = {
|
||||||
@ -135,7 +135,7 @@ Bird: ([fly distance:F64] [land])
|
|||||||
|
|
||||||
func TestAssignmentLiteralErrInterfaceArray (test *testing.T) {
|
func TestAssignmentLiteralErrInterfaceArray (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"cannot use array literal as Bird", 6, 2,
|
"cannot use array literal as Bird", 4, 11,
|
||||||
`
|
`
|
||||||
Bird: ([fly distance:F64] [land])
|
Bird: ([fly distance:F64] [land])
|
||||||
[main] = {
|
[main] = {
|
||||||
@ -146,11 +146,9 @@ Bird: ([fly distance:F64] [land])
|
|||||||
|
|
||||||
func TestAssignmentLiteralErrInterfaceStruct (test *testing.T) {
|
func TestAssignmentLiteralErrInterfaceStruct (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"cannot assign literal to interface", 6, 2,
|
"cannot use struct literal as Bird", 4, 11,
|
||||||
`
|
`
|
||||||
Bird: ([fly distance:F64] [land])
|
Bird: ([fly distance:F64] [land])
|
||||||
BlueJay: Int
|
|
||||||
BlueJay::[land] = { }
|
|
||||||
[main] = {
|
[main] = {
|
||||||
b:Bird = (x: 5 y: 6)
|
b:Bird = (x: 5 y: 6)
|
||||||
}
|
}
|
||||||
|
@ -54,21 +54,21 @@ func (this *Tree) analyzeLiteralArray (
|
|||||||
entity.Expression,
|
entity.Expression,
|
||||||
error,
|
error,
|
||||||
) {
|
) {
|
||||||
into = this.reduceToBase(into)
|
base := this.reduceToBase(into)
|
||||||
var elementType entity.Type
|
var elementType entity.Type
|
||||||
switch into.(type) {
|
switch base.(type) {
|
||||||
case *entity.TypeArray:
|
case *entity.TypeArray:
|
||||||
into := into.(*entity.TypeArray)
|
base := base.(*entity.TypeArray)
|
||||||
if into.Length != len(literal.Elements) {
|
if base.Length != len(literal.Elements) {
|
||||||
return nil, participle.Errorf (
|
return nil, participle.Errorf (
|
||||||
literal.Pos, "expected %v elements",
|
literal.Pos, "expected %v elements",
|
||||||
into.Length)
|
base.Length)
|
||||||
}
|
}
|
||||||
elementType = into.Element
|
elementType = base.Element
|
||||||
|
|
||||||
case *entity.TypeSlice:
|
case *entity.TypeSlice:
|
||||||
into := into.(*entity.TypeSlice)
|
base := base.(*entity.TypeSlice)
|
||||||
elementType = into.Element
|
elementType = base.Element
|
||||||
default:
|
default:
|
||||||
return nil, participle.Errorf (
|
return nil, participle.Errorf (
|
||||||
literal.Pos, "cannot use array literal as %v",
|
literal.Pos, "cannot use array literal as %v",
|
||||||
|
Loading…
Reference in New Issue
Block a user