Skip to content

Commit

Permalink
build with latest generics cl
Browse files Browse the repository at this point in the history
  • Loading branch information
ccbrown committed Aug 17, 2019
1 parent b29cacc commit e70023c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Binary file modified experimental/generics/cmd/preprocess.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions experimental/generics/preprocessor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func preprocess(node ast.Node, info *types.Info, parentTypeParams map[string]typ
}
generatedDecls[name] = nil
decl = preprocess(decl, info, parentTypeParams).(*ast.FuncDecl)
decl.TParams = nil
generatedDecls[name] = decl
}

Expand Down Expand Up @@ -248,6 +249,7 @@ func preprocess(node ast.Node, info *types.Info, parentTypeParams map[string]typ
}
return true
}, nil).(*ast.TypeSpec)
spec.TParams = nil
spec.Name = ast.NewIdent(name)
generatedDecls[name] = &ast.GenDecl{
Tok: token.TYPE,
Expand Down
42 changes: 42 additions & 0 deletions experimental/generics/preprocessor/testdata/playground-default.go2
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

// XXX: This is highly experimental. Don't expect correctness or stability.

// Takes a slice of any type and reverses it.
func Reverse (type T) (list []T) {
i := 0
j := len(list) - 1
for i < j {
list[i], list[j] = list[j], list[i]
i++
j--
}
}

// Requires T to be a string or byte slice.
//
// Note that at the moment, contracts are not actually type-checked.
contract Sequence(T) {
T string, []byte
}

// Defines a tree where each node can hold a value that satisfies Sequence.
type Tree (type T Sequence) struct {
Left *Tree
Right *Tree
Value T
}

func main() {
s := []string{"a", "b", "c"}
Reverse(s)
println(s[0], s[1], s[2])

tree := Tree(string){
Value: "foo",
Left: &Tree(string){
Value: "bar",
},
}
println(tree.Left.Value)
}

0 comments on commit e70023c

Please sign in to comment.