Skip to content

Commit

Permalink
split type(nil)
Browse files Browse the repository at this point in the history
  • Loading branch information
ltzmaxwell committed Apr 4, 2024
1 parent 953765c commit 05849f0
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 106 deletions.
9 changes: 0 additions & 9 deletions gnovm/pkg/gnolang/op_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,6 @@ func (m *Machine) doOpStaticTypeOf() {
}

switch path.Type {
case VPUverse:
println("---case match vpuverse")
switch path.Depth {
case 0:
println("---depth is 0")
dxt = xt
default:
panic("should not happen")
}
case VPBlock:
switch dxt.(type) {
case *PackageType:
Expand Down
35 changes: 7 additions & 28 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,21 +1030,8 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
panic("type conversion requires single argument")
}
n.NumArgs = 1
var dt Type
ct := evalStaticType(store, last, n.Func)
//switch arg0 := n.Args[0].(type) {
if arg0, ok := n.Args[0].(*ConstExpr); ok {
// check legal type for nil
if arg0.IsUndefined() {
switch ct.Kind() { // special case for nil conversion check. refer to 0f47a
case SliceKind, PointerKind, FuncKind, MapKind, InterfaceKind:
dt = ct // convert nil to typed-nil
default:
panic(fmt.Sprintf(
"cannot convert %v to %v",
arg0, ct.Kind()))
}
}
ct := evalStaticType(store, last, n.Func)
// As a special case, if a decimal cannot
// be represented as an integer, it cannot be converted to one,
// and the error is handled here.
Expand All @@ -1064,19 +1051,18 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
// TODO: consider this, need check?
// (const) untyped decimal -> float64.
// (const) untyped bigint -> int.
convertConst(store, last, arg0, dt) // convert to default type if dt is nil
convertConst(store, last, arg0, nil)
// evaluate the new expression.
cx := evalConst(store, last, n)
// Though cx may be undefined if ct is interface,
// the ATTR_TYPEOF_VALUE is still interface.
cx.SetAttribute(ATTR_TYPEOF_VALUE, dt)
cx.SetAttribute(ATTR_TYPEOF_VALUE, ct)
return cx, TRANS_CONTINUE
} else {
ct := evalStaticType(store, last, n.Func)
n.SetAttribute(ATTR_TYPEOF_VALUE, ct)
return n, TRANS_CONTINUE
}
// general case, for non-const untyped && no nested untyped shift
// after handling const, and special cases recursively, set the target node type
// ct := evalStaticType(store, last, n.Func)
n.SetAttribute(ATTR_TYPEOF_VALUE, ct)
return n, TRANS_CONTINUE
default:
panic(fmt.Sprintf(
"unexpected func type %v (%v)",
Expand Down Expand Up @@ -2476,13 +2462,6 @@ func convertIfConst(store Store, last BlockNode, x Expr) {

func convertConst(store Store, last BlockNode, cx *ConstExpr, t Type) {
if t != nil && t.Kind() == InterfaceKind {
if cx.IsUndefined() && cx.T == nil { // if cx is nil, not undefined interface
if _, ok := t.(*NativeType); !ok { // bypass native nil interface, not support native interface(nil) now
ConvertTo(nilAllocator, store, &cx.TypedValue, t)
setConstAttrs(cx)
return
}
}
t = nil
}
if isUntyped(cx.T) {
Expand Down
5 changes: 0 additions & 5 deletions gnovm/pkg/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ GNO_CASE:
// special case for interface target
// see: go.dev/issue/13061
if t.Kind() == InterfaceKind {
if tv.IsUndefined() && tv.T == nil { // see 0f47f
if _, ok := t.(*NativeType); !ok { // no support for native now
tv.T = t
}
}
return
}
// special case for undefined/nil source
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/interface27b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ func main() {
}

// Output:
// map{(0 int):(undefined) .uverse.error}
// map{(0 int):(undefined) nil}
2 changes: 1 addition & 1 deletion gnovm/tests/files/interface28b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ func main() {
}

// Output:
// slice[(undefined) .uverse.error]
// slice[(undefined) nil]
18 changes: 0 additions & 18 deletions gnovm/tests/files/types/0f47_nilcast_filetest.gno

This file was deleted.

10 changes: 0 additions & 10 deletions gnovm/tests/files/types/0f47a_filetest.gno

This file was deleted.

20 changes: 0 additions & 20 deletions gnovm/tests/files/types/0f47c_filetest.gno

This file was deleted.

2 changes: 1 addition & 1 deletion gnovm/tests/files/types/0f47f_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func main() {
}

// Output:
// false
// true
// <nil>
16 changes: 3 additions & 13 deletions gnovm/tests/files/zrealm1.gno
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,8 @@ func main() {
// "value": "somekey"
// }
// },
// {
// "T": {
// "@type": "/gno.RefType",
// "ID": "gno.land/r/test.Node"
// }
// },
// {
// "T": {
// "@type": "/gno.RefType",
// "ID": "gno.land/r/test.Node"
// }
// }
// {},
// {}
// ],
// "ObjectInfo": {
// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4",
Expand Down Expand Up @@ -205,7 +195,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "5684cb2d35e7da2ec67cf7a389db879a44bb4d30",
// "Hash": "ae4e9e2d205cc0081d4ee249e1d188ebe270b220",
// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4"
// }
// }
Expand Down

0 comments on commit 05849f0

Please sign in to comment.