{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/go/issues/25189","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/25189/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/25189/comments","events_url":"https://api.github.com/repos/golang/go/issues/25189/events","html_url":"https://github.com/golang/go/issues/25189","id":319026196,"number":25189,"title":"cmd/compile: elide useless type assertion","user":{"login":"dsnet","id":6354026,"avatar_url":"https://avatars1.githubusercontent.com/u/6354026?v=4","gravatar_id":"","url":"https://api.github.com/users/dsnet","html_url":"https://github.com/dsnet","followers_url":"https://api.github.com/users/dsnet/followers","following_url":"https://api.github.com/users/dsnet/following{/other_user}","gists_url":"https://api.github.com/users/dsnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dsnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsnet/subscriptions","organizations_url":"https://api.github.com/users/dsnet/orgs","repos_url":"https://api.github.com/users/dsnet/repos","events_url":"https://api.github.com/users/dsnet/events{/privacy}","received_events_url":"https://api.github.com/users/dsnet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-30T20:34:31Z","updated_at":"2018-04-30T20:34:31Z","closed_at":null,"author_association":"MEMBER","body":"Consider the following:\r\n```go\r\ntype CustomUnmarshaler interface {\r\n\tCustomUnmarshal([]byte) error\r\n}\r\n\r\ntype MyMessage struct{}\r\n\r\nfunc (m *MyMessage) Unmarshal(b []byte) error {\r\n\tif u, ok := (interface{})(m).(CustomUnmarshaler); ok {\r\n\t\treturn u.CustomUnmarshal(b)\r\n\t}\r\n\treturn nil\r\n}\r\n```\r\n\r\nIn this situation, the compiler knows that the `MyMessage` type has no `CustomUnmarshal` method, so the type assertion cannot possibly succeed. In this case, the condition of the if statement can be statically determined and the body be considered dead code.\r\n\r\nHowever, a tip build of the compiler continues to emit code for the assertion.\r\n```\r\n0x0021 00033 (/tmp/main.go:10)\tLEAQ\ttype.\"\".CustomUnmarshaler(SB), AX\r\n0x0028 00040 (/tmp/main.go:10)\tMOVQ\tAX, (SP)\r\n0x002c 00044 (/tmp/main.go:10)\tLEAQ\ttype.*\"\".Foo(SB), AX\r\n0x0033 00051 (/tmp/main.go:10)\tMOVQ\tAX, 8(SP)\r\n0x0038 00056 (/tmp/main.go:9)\tMOVQ\t\"\".f+64(SP), AX\r\n0x003d 00061 (/tmp/main.go:10)\tMOVQ\tAX, 16(SP)\r\n0x0042 00066 (/tmp/main.go:10)\tPCDATA\t$0, $1\r\n0x0042 00066 (/tmp/main.go:10)\tCALL\truntime.assertE2I2(SB)\r\n0x0047 00071 (/tmp/main.go:10)\tMOVQ\t24(SP), AX\r\n0x004c 00076 (/tmp/main.go:10)\tMOVQ\t32(SP), CX\r\n0x0051 00081 (/tmp/main.go:10)\tLEAQ\t40(SP), DX\r\n0x0056 00086 (/tmp/main.go:10)\tCMPB\t(DX), $0\r\n0x0059 00089 (/tmp/main.go:10)\tJEQ\t161\r\n0x005b 00091 (/tmp/main.go:11)\tMOVQ\t24(AX), AX\r\n0x005f 00095 (/tmp/main.go:11)\tMOVQ\t\"\".b+72(SP), DX\r\n0x0064 00100 (/tmp/main.go:11)\tMOVQ\tDX, 8(SP)\r\n0x0069 00105 (/tmp/main.go:11)\tMOVQ\t\"\".b+80(SP), DX\r\n0x006e 00110 (/tmp/main.go:11)\tMOVQ\tDX, 16(SP)\r\n0x0073 00115 (/tmp/main.go:11)\tMOVQ\t\"\".b+88(SP), DX\r\n0x0078 00120 (/tmp/main.go:11)\tMOVQ\tDX, 24(SP)\r\n0x007d 00125 (/tmp/main.go:11)\tMOVQ\tCX, (SP)\r\n0x0081 00129 (/tmp/main.go:11)\tPCDATA\t$0, $2\r\n0x0081 00129 (/tmp/main.go:11)\tCALL\tAX\r\n0x0083 00131 (/tmp/main.go:11)\tMOVQ\t32(SP), AX\r\n0x0088 00136 (/tmp/main.go:11)\tMOVQ\t40(SP), CX\r\n0x008d 00141 (/tmp/main.go:11)\tMOVQ\tAX, \"\".~r1+96(SP)\r\n0x0092 00146 (/tmp/main.go:11)\tMOVQ\tCX, \"\".~r1+104(SP)\r\n0x0097 00151 (/tmp/main.go:11)\tMOVQ\t48(SP), BP\r\n0x009c 00156 (/tmp/main.go:11)\tADDQ\t$56, SP\r\n0x00a0 00160 (/tmp/main.go:11)\tRET\r\n```"}}
{"actor":{"display_login":"dsnet"}}