Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(28)

Unified Diff: 2014/static-analysis/demo.go

Issue 172590043: code review 172590043: 2014/static-analysis: add slides for gomeetup presentation. (Closed)
Patch Set: diff -r 1a303e2eaf127ae0a75d5998b44f719d8f3e6176 https://code.google.com/p/go.talks Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 2014/static-analysis.slide ('k') | 2014/static-analysis/demoscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: 2014/static-analysis/demo.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/2014/static-analysis/demo.go
@@ -0,0 +1,41 @@
+package main
+
+import "fmt"
+
+type Leaf int
+
+func (l Leaf) Sum() int { return int(l) }
+func (l Leaf) String() string { return fmt.Sprintf("%d", l) }
+
+type Branch struct{ left, rhs Tree }
+
+func (b *Branch) Sum() int { return b.left.Sum() + b.rhs.Sum() }
+func (b *Branch) String() string { return fmt.Sprintf("(%s, %s)", b.left, b.rhs) }
+
+type Tree interface {
+ Sum() int
+}
+
+func main() {
+ var tree Tree = Leaf(42)
+ fmt.Println(tree.Sum())
+
+ if unknown {
+ tree = &Branch{tree, Leaf(123)}
+ }
+ fmt.Println(tree.Sum())
+ fmt.Println(tree)
+}
+
+var unknown bool
+
+//
+
+func _() {
+ type Answer struct{ right bool }
+ var x struct {
+ Answer
+ Branch
+ }
+ fmt.Println(x.right)
+}
« no previous file with comments | « 2014/static-analysis.slide ('k') | 2014/static-analysis/demoscript » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b