Permalink
Browse files

Play with type aliases of Go 1.9.

  • Loading branch information...
dmitshur committed Sep 1, 2017
1 parent e6af3ea commit 55cedbb2f3cd3c834685ca3c64eb1d9b686d4d97
Showing with 82 additions and 0 deletions.
  1. +39 −0 230/lib/lib.go
  2. +36 −0 230/main.go
  3. +7 −0 230/p/p.go
View
@@ -0,0 +1,39 @@
package lib
import (
"fmt"
"github.com/shurcooL/play/230/p"
)
type (
NN p.N
AN = p.N
NA p.A
AA = p.A
)
type X struct {
S string
}
type A = X
func (a A) Method() string {
return "method: " + a.S
}
func DoStuff() {
var nn NN = "value"
fmt.Printf("%T %v\n", nn, nn)
var an AN = "value"
fmt.Printf("%T %v\n", an, an)
var na NA = "value"
fmt.Printf("%T %v\n", na, na)
var aa AA = "value"
fmt.Printf("%T %v\n", aa, aa)
}
View
@@ -0,0 +1,36 @@
package main
import (
"fmt"
"github.com/shurcooL/play/230/lib"
)
type X struct {
S string
}
func (x X) MethodOnType() string {
return "type method: " + x.S
}
type A = X
func (a A) MethodOnAlias() string {
return "alias method: " + a.S
}
func main() {
var a A = A{S: "aliases working"}
fmt.Printf("%T\n", a)
fmt.Println(a)
fmt.Println(a.MethodOnType())
fmt.Println(a.MethodOnAlias())
//var la lib.A = lib.A{S: "aliases working"}
//fmt.Printf("%T %v %v\n", la, la, la.Method())
//fmt.Println(runtime.Version())
lib.DoStuff()
}
View
@@ -0,0 +1,7 @@
package p
type T string
type N T
type A = T

0 comments on commit 55cedbb

Please sign in to comment.