github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/examples/bugs.ipynb (about) 1 { 2 "cells": [ 3 { 4 "cell_type": "markdown", 5 "metadata": {}, 6 "source": [ 7 "# <span style=\"color:green\">Fixed</span>: Can not use a method of an instance if the instance and the type are defined separately\n", 8 "- [bug](https://github.com/yunabe/lgo/issues/11)" 9 ] 10 }, 11 { 12 "cell_type": "code", 13 "execution_count": null, 14 "metadata": {}, 15 "outputs": [], 16 "source": [ 17 "type Data struct {\n", 18 " value string\n", 19 "}\n", 20 "\n", 21 "func (d Data) Value() string {\n", 22 " return d.value\n", 23 "}\n", 24 "\n", 25 "type WithValue interface {\n", 26 " Value() string\n", 27 "}" 28 ] 29 }, 30 { 31 "cell_type": "code", 32 "execution_count": null, 33 "metadata": {}, 34 "outputs": [], 35 "source": [ 36 "d := Data{\"hello\"}" 37 ] 38 }, 39 { 40 "cell_type": "code", 41 "execution_count": 3, 42 "metadata": {}, 43 "outputs": [ 44 { 45 "name": "stdout", 46 "output_type": "stream", 47 "text": [ 48 "hello\n" 49 ] 50 } 51 ], 52 "source": [ 53 "// Got a link error because of https://github.com/golang/go/issues/22998\n", 54 "d.Value()" 55 ] 56 }, 57 { 58 "cell_type": "code", 59 "execution_count": null, 60 "metadata": {}, 61 "outputs": [ 62 { 63 "name": "stdout", 64 "output_type": "stream", 65 "text": [ 66 "hello\n" 67 ] 68 } 69 ], 70 "source": [ 71 "// This works without any problem.\n", 72 "WithValue(d).Value()" 73 ] 74 }, 75 { 76 "cell_type": "markdown", 77 "metadata": {}, 78 "source": [ 79 "# <span style=\"color:green\">Fixed</span>: goroutines should be canceled when the main routine ends\n", 80 "- [bug](https://github.com/yunabe/lgo/issues/6)" 81 ] 82 }, 83 { 84 "cell_type": "code", 85 "execution_count": null, 86 "metadata": {}, 87 "outputs": [ 88 { 89 "name": "stdout", 90 "output_type": "stream", 91 "text": [ 92 "Canceled\n" 93 ] 94 } 95 ], 96 "source": [ 97 "import (\n", 98 " \"fmt\"\n", 99 ")\n", 100 "\n", 101 "i := 0\n", 102 "go func() {\n", 103 " defer func() {\n", 104 " fmt.Println(\"Canceled\")\n", 105 " }()\n", 106 " for i = 0;; i++ {}\n", 107 "}()" 108 ] 109 }, 110 { 111 "cell_type": "markdown", 112 "metadata": {}, 113 "source": [ 114 "# <span style=\"color:green\">Fixed</span>: The entire process terminated when a go routine panics\n", 115 "- [bug](https://github.com/yunabe/lgo/issues/5)" 116 ] 117 }, 118 { 119 "cell_type": "code", 120 "execution_count": null, 121 "metadata": {}, 122 "outputs": [ 123 { 124 "name": "stderr", 125 "output_type": "stream", 126 "text": [ 127 "panic: die!\n", 128 "\n", 129 "goroutine 26 [running]:\n", 130 "runtime/debug.Stack(0xc4203f9eb8, 0x7fc12a067bc0, 0xc42003a010)\n", 131 "\t/usr/lib/go-1.8/src/runtime/debug/stack.go:24 +0x7b\n", 132 "github.com/yunabe/lgo/core.FinalizeGoRoutine()\n", 133 "\t/home/yunabe/local/gocode/src/github.com/yunabe/lgo/core/core.go:81 +0x64\n", 134 "panic(0x7fc12a067bc0, 0xc42003a010)\n", 135 "\t/usr/lib/go-1.8/src/runtime/panic.go:489 +0x2e7\n", 136 "github.com/yunabe/lgo/sess7b2274696d65223a313530383530393332323132383131303736397d/exec8.lgo_init.func1.1()\n", 137 "\t/home/yunabe/local/gocode/src/github.com/yunabe/lgo/sess7b2274696d65223a313530383530393332323132383131303736397d/exec8/src.go:13 +0x66\n", 138 "github.com/yunabe/lgo/sess7b2274696d65223a313530383530393332323132383131303736397d/exec8.lgo_init.func1()\n", 139 "\t/home/yunabe/local/gocode/src/github.com/yunabe/lgo/sess7b2274696d65223a313530383530393332323132383131303736397d/exec8/src.go:14 +0x40\n", 140 "created by github.com/yunabe/lgo/sess7b2274696d65223a313530383530393332323132383131303736397d/exec8.lgo_init\n", 141 "\t/home/yunabe/local/gocode/src/github.com/yunabe/lgo/sess7b2274696d65223a313530383530393332323132383131303736397d/exec8/src.go:15 +0x3b\n" 142 ] 143 }, 144 { 145 "name": "stdout", 146 "output_type": "stream", 147 "text": [ 148 "main done\n", 149 "10\n", 150 "<nil>\n" 151 ] 152 } 153 ], 154 "source": [ 155 "import (\n", 156 " \"fmt\"\n", 157 " \"time\"\n", 158 ")\n", 159 "\n", 160 "go func() {\n", 161 " panic(\"die!\")\n", 162 "}()\n", 163 "\n", 164 "time.Sleep(100 * time.Millisecond)\n", 165 "fmt.Println(\"main done\")" 166 ] 167 }, 168 { 169 "cell_type": "markdown", 170 "metadata": {}, 171 "source": [ 172 "# <span style=\"color:green\">Fixed</span>: interface is not working\n", 173 "If you invoke a method through an interface in lgo, it crashes with `runtime error: invalid memory address or nil pointer dereference` ([bug](https://github.com/yunabe/lgo/issues/3))." 174 ] 175 }, 176 { 177 "cell_type": "code", 178 "execution_count": null, 179 "metadata": {}, 180 "outputs": [ 181 { 182 "name": "stdout", 183 "output_type": "stream", 184 "text": [ 185 "---- 1 ----\n", 186 "Hello, I'm yunabe.\n", 187 "---- 2 ----\n", 188 "Hello, I'm yunabe.\n" 189 ] 190 } 191 ], 192 "source": [ 193 "import (\n", 194 " \"fmt\"\n", 195 ")\n", 196 "\n", 197 "type Hello interface {\n", 198 " SayHello()\n", 199 "}\n", 200 "\n", 201 "type person struct {\n", 202 " name string\n", 203 "}\n", 204 "\n", 205 "func (p *person) SayHello() {\n", 206 " fmt.Printf(\"Hello, I'm %s.\\n\", p.name)\n", 207 "}\n", 208 "\n", 209 "p := person{\"yunabe\"}\n", 210 "fmt.Println(\"---- 1 ----\")\n", 211 "p.SayHello()\n", 212 "\n", 213 "var h Hello = &p\n", 214 "fmt.Println(\"---- 2 ----\")\n", 215 "h.SayHello()" 216 ] 217 }, 218 { 219 "cell_type": "markdown", 220 "metadata": {}, 221 "source": [ 222 "# <span style=\"color:green\">Fixed</span>: GC crashes with a fatal error\n", 223 "The following crashes with `fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?)` message ([bug](https://github.com/yunabe/lgo/issues/2))." 224 ] 225 }, 226 { 227 "cell_type": "code", 228 "execution_count": null, 229 "metadata": { 230 "collapsed": true 231 }, 232 "outputs": [], 233 "source": [ 234 "import (\n", 235 " \"fmt\"\n", 236 " \"log\"\n", 237 " \"runtime\"\n", 238 " \"runtime/debug\"\n", 239 ")\n", 240 "\n", 241 "type MyData struct {\n", 242 " b []byte\n", 243 "}\n", 244 "\n", 245 "func (m *MyData) Size() int {\n", 246 " return len(m.b)\n", 247 "}\n", 248 "\n", 249 "func NewMyData() *MyData {\n", 250 " return &MyData{\n", 251 " b: make([]byte, 10 * (1 << 20)),\n", 252 " }\n", 253 "}\n", 254 "\n", 255 "var l []*MyData\n", 256 "for i := 0; i < 100; i++ {\n", 257 " d := NewMyData()\n", 258 " l = append(l, d)\n", 259 "}\n", 260 "l = nil\n", 261 "debug.FreeOSMemory()\n", 262 "runtime.GC()" 263 ] 264 }, 265 { 266 "cell_type": "markdown", 267 "metadata": {}, 268 "source": [ 269 "# <span style=\"color:green\">Fixed</span>: functions and arguments in go statement are not bound immediately\n", 270 "The following code must output `goroutine: 0`, `goroutine: 1` and `goroutine: 2` in a random order.\n", 271 "But `lgo` shows `goroutine: 3` three times ([bug](https://github.com/yunabe/lgo/issues/73))." 272 ] 273 }, 274 { 275 "cell_type": "code", 276 "execution_count": null, 277 "metadata": {}, 278 "outputs": [ 279 { 280 "name": "stdout", 281 "output_type": "stream", 282 "text": [ 283 "goroutine: 2\n", 284 "goroutine: 1\n", 285 "goroutine: 0\n" 286 ] 287 } 288 ], 289 "source": [ 290 "import (\n", 291 " \"fmt\"\n", 292 ")\n", 293 "\n", 294 "for i := 0; i < 3; i++ {\n", 295 " go func(id int) {\n", 296 " fmt.Println(\"goroutine:\", id)\n", 297 " }(i)\n", 298 "}" 299 ] 300 } 301 ], 302 "metadata": { 303 "kernelspec": { 304 "display_name": "Go (lgo)", 305 "language": "go", 306 "name": "lgo" 307 }, 308 "language_info": { 309 "file_extension": "", 310 "mimetype": "", 311 "name": "go", 312 "version": "" 313 } 314 }, 315 "nbformat": 4, 316 "nbformat_minor": 2 317 }