Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix declaredtype preprocess #2

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main



type nat []int

func main() {

var nlist = nat{0}
var ulist = []int{1}
var n int = 3

a := append(nlist, n)
b := append(ulist, n)

println(a)
println(b)

a = append(ulist, n)
b = append(nlist, n)

c := append(nlist, ulist...)
d := append(ulist, nlist...)

println(a)
println(b)
println(c)
println(d)

}

// Output:
// (slice[(0 int),(3 int)] main.nat)
// slice[(1 int),(3 int)]
// (slice[(1 int),(3 int)] main.nat)
// slice[(0 int),(3 int)]
// (slice[(0 int),(1 int)] main.nat)
// slice[(1 int),(0 int)]
15 changes: 15 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype0_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

type nat []word
type word int

func main() {
var a nat
b := []word{0}
a = b

println(a)
}

// Output:
// (slice[(0 main.word)] main.nat)
15 changes: 15 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype0b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

type nat []int
type word int

func main() {
var a nat
b := []word{0}
a = b

println(a)
}

// Error:
// main/contracts/assign_unnamed_type/assign_unnamedtype0b_filetest.gno:9: cannot use main.word as int without explicit conversion
26 changes: 26 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype1_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

type nat []int

func main() {

var a nat
a = []int{0}
b := []int{1}

println(a)
println(b)

a = nat{0}
b = a

println(a)
println(b)

}

// Output:
// (slice[(0 int)] main.nat)
// slice[(1 int)]
// (slice[(0 int)] main.nat)
// slice[(0 int)]
26 changes: 26 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype1a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

type nat []int

func (n nat) zero(num []int) {
println(num)

}

func (n nat) one(num nat) {

println(num)
}

func main() {
var a nat
a = []int{}

a.zero(nat{0})
a.one([]int{1})

}

// Output:
// slice[(0 int)]
// (slice[(1 int)] main.nat)
30 changes: 30 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype1b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

type nat []int

func (n nat) zero() nat {

return []int{0}
}

func (n nat) one() []int {

return nat{1}
}

func main() {
var a nat
a = []int{}

println(a.zero())
println(a.zero().zero())
println(a.zero().one())
println(a.one())

}

// Output:
// (slice[(0 int)] main.nat)
// (slice[(0 int)] main.nat)
// slice[(1 int)]
// slice[(1 int)]
28 changes: 28 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype1c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

type nat []int

func (n nat) zero() interface{} {

return []int{0}
}

func (n nat) one() interface{} {

return nat{1}
}

func main() {
var a nat
a = []int{}

println(a.zero())
println(a.one())
println(a.one().(nat).zero())

}

// Output:
// slice[(0 int)]
// (slice[(1 int)] main.nat)
// slice[(0 int)]
25 changes: 25 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype2_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

type nat [1]int

func main() {

var a nat
a = [1]int{0}
b := [1]int{1}

println(a)
println(b)
a = nat{0}
b = a

println(a)
println(b)

}

// Output:
// (array[(0 int)] main.nat)
// array[(1 int)]
// (array[(0 int)] main.nat)
// array[(0 int)]
26 changes: 26 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype2a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

type nat [1]int

func (n nat) zero(num [1]int) {
println(num)

}

func (n nat) one(num nat) {

println(num)
}

func main() {
var a nat
a = [1]int{}

a.zero(nat{0})
a.one([1]int{1})

}

// Output:
// array[(0 int)]
// (array[(1 int)] main.nat)
30 changes: 30 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype2b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

type nat [1]int

func (n nat) zero() nat {

return [1]int{0}
}

func (n nat) one() [1]int {

return nat{1}
}

func main() {
var a nat
a = [1]int{}

println(a.zero())
println(a.zero().zero())
println(a.zero().one())
println(a.one())

}

// Output:
// (array[(0 int)] main.nat)
// (array[(0 int)] main.nat)
// array[(1 int)]
// array[(1 int)]
28 changes: 28 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype2c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

type nat [1]int

func (n nat) zero() interface{} {

return [1]int{0}
}

func (n nat) one() interface{} {

return nat{1}
}

func main() {
var a nat
a = [1]int{}

println(a.zero())
println(a.one())
println(a.one().(nat).zero())

}

// Output:
// array[(0 int)]
// (array[(1 int)] main.nat)
// array[(0 int)]
27 changes: 27 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype3_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

type nat struct {
num int
}

func main() {

var a nat
a = struct{ num int }{0}
b := struct{ num int }{1}

println(a)
println(b)
a = nat{0}
b = a

println(a)
println(b)

}

// Output:
// (struct{(0 int)} main.nat)
// struct{(1 int)}
// (struct{(0 int)} main.nat)
// struct{(0 int)}
28 changes: 28 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype3a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

type nat struct {
num int
}

func (n nat) zero(num struct{ num int }) {
println(num)

}

func (n nat) one(num nat) {

println(num)
}

func main() {
var a nat
a = struct{ num int }{0}

a.zero(nat{0})
a.one(struct{ num int }{1})

}

// Output:
// struct{(0 int)}
// (struct{(1 int)} main.nat)
32 changes: 32 additions & 0 deletions contracts/assign_unnamed_type/assign_unnamedtype3b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

type nat struct {
num int
}

func (n nat) zero() nat {

return struct{ num int }{0}
}

func (n nat) one() struct{ num int } {

return nat{1}
}

func main() {
var a nat
a = struct{ num int }{}

println(a.zero())
println(a.zero().zero())
println(a.zero().one())
println(a.one())

}

// Output:
// (struct{(0 int)} main.nat)
// (struct{(0 int)} main.nat)
// struct{(1 int)}
// struct{(1 int)}
Loading
Loading