~mna/snow

4dd13484288457ae64c0e9e9582d5b5d29c78360 — Martin Angers 1 year, 8 months ago 74be30b
pkg/codegen: add generic tests
A pkg/codegen/testdata/fn_generic_external.snow => pkg/codegen/testdata/fn_generic_external.snow +14 -0
@@ 0,0 1,14 @@
@extern(import: "fmt", symbol: "Println")
fn println [$T] (v: $T)

fn main() {
  println [int] (1)
  println [string] ("hello")
  println [bool] (true)
  println [int] (2)
}

#=1
#=hello
#=true
#=2

A pkg/codegen/testdata/fn_generic_external.snow.err => pkg/codegen/testdata/fn_generic_external.snow.err +0 -0
A pkg/codegen/testdata/fn_generic_external.snow.want => pkg/codegen/testdata/fn_generic_external.snow.want +28 -0
@@ 0,0 1,28 @@
package main

import "fmt"

func _اprintlnا0(
	v int,
) {
	fmt.Println(v)
}

func _اprintlnا1(
	v string,
) {
	fmt.Println(v)
}

func _اprintlnا2(
	v bool,
) {
	fmt.Println(v)
}

func main() {
	_اprintlnا0(1)
	_اprintlnا1("hello")
	_اprintlnا2(true)
	_اprintlnا0(2)
}

A pkg/codegen/testdata/struct_unused_generic.snow => pkg/codegen/testdata/struct_unused_generic.snow +21 -0
@@ 0,0 1,21 @@
struct A[$T] {
  let x: $T

  struct B[$U] {
    let y: $U

    struct C[$V] {
      let z: $V
    }
  }
}

fn main() {
  let c = A.B.C[int](z: 1)
  println(c.z)
}

@extern(import: "fmt", symbol: "Println")
fn println(i: int)

#=1

A pkg/codegen/testdata/struct_unused_generic.snow.err => pkg/codegen/testdata/struct_unused_generic.snow.err +0 -0
A pkg/codegen/testdata/struct_unused_generic.snow.want => pkg/codegen/testdata/struct_unused_generic.snow.want +29 -0
@@ 0,0 1,29 @@
package main

import "fmt"

type _ا5اCا0 struct {
	_اz int
}

func _ا5اCا0اnew(
	s _ا5اCا0,
	m map[string]bool,
) _ا5اCا0 {
	var r _ا5اCا0
	if m["z"] {
		r._اz = s._اz
	}
	return r
}

func main() {
	var c _ا5اCا0 = _ا5اCا0اnew(_ا5اCا0{_اz: 1}, map[string]bool{"z": true})
	_اprintln(c._اz)
}

func _اprintln(
	i int,
) {
	fmt.Println(i)
}