{"action":"closed","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/25782","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/25782/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/25782/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/25782/events","html_url":"https://github.com/dart-lang/sdk/issues/25782","id":133801113,"number":25782,"title":"AssertAssignableInstr::Canonicalize sometimes creates checks against TypeRef which runtime can't handle","user":{"login":"mraleph","id":131846,"avatar_url":"https://avatars.githubusercontent.com/u/131846?v=3","gravatar_id":"","url":"https://api.github.com/users/mraleph","html_url":"https://github.com/mraleph","followers_url":"https://api.github.com/users/mraleph/followers","following_url":"https://api.github.com/users/mraleph/following{/other_user}","gists_url":"https://api.github.com/users/mraleph/gists{/gist_id}","starred_url":"https://api.github.com/users/mraleph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mraleph/subscriptions","organizations_url":"https://api.github.com/users/mraleph/orgs","repos_url":"https://api.github.com/users/mraleph/repos","events_url":"https://api.github.com/users/mraleph/events{/privacy}","received_events_url":"https://api.github.com/users/mraleph/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-vm","name":"area-vm","color":"c7def8"}],"state":"closed","locked":false,"assignee":{"login":"mraleph","id":131846,"avatar_url":"https://avatars.githubusercontent.com/u/131846?v=3","gravatar_id":"","url":"https://api.github.com/users/mraleph","html_url":"https://github.com/mraleph","followers_url":"https://api.github.com/users/mraleph/followers","following_url":"https://api.github.com/users/mraleph/following{/other_user}","gists_url":"https://api.github.com/users/mraleph/gists{/gist_id}","starred_url":"https://api.github.com/users/mraleph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mraleph/subscriptions","organizations_url":"https://api.github.com/users/mraleph/orgs","repos_url":"https://api.github.com/users/mraleph/repos","events_url":"https://api.github.com/users/mraleph/events{/privacy}","received_events_url":"https://api.github.com/users/mraleph/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-02-15T19:48:33Z","updated_at":"2016-02-16T12:45:00Z","closed_at":"2016-02-16T12:45:00Z","body":"In the optimized version of the function `f` from the reproduction below compiler ends up generating `AssertAssignable:6(v3, TypeRef: B<...> (@0xf5d8f331 Hefbb15c), 'field' instantiator_type_arguments(v0))` because `AssertAssignableInstr::Canonicalize` replaces destination type of the original `AssertAssignable` against type parameter with whatever `InstantiateFrom` returned (and it returns `TypeRef`). However `Instance::IsInstanceOf` (which is called in the runtime function `TypeCheck`) apparently can't cope with `dst_type` being  `TypeRef` - it returns `false` even though it would return true if we unwrap the ref.\r\n\r\nEither optimizing compiler needs to take care and unwrap `TypeRef` when canonicalizing or runtime system must be able to cope with `TypeRef`s passed to `IsInstanceOf`.\r\n\r\nNote: this issue causes flakiness on the dart2js buildbot. \r\n\r\n/cc @whesse @asgerf @rakudrama @fsc8000 @crelier \r\n\r\n```dart\r\n// VMOptions=--enable_asserts --enable_type_checks --enable-inlining-annotations --optimization-counter-threshold=10\r\n\r\nconst AlwaysInline = \"AlwaysInline\";\r\nconst NeverInline = \"NeverInline\";\r\n\r\nabstract class A<T extends A<T>> {\r\n  @AlwaysInline\r\n  m(x) => new R<T>(x);\r\n}\r\n\r\nclass B extends A<B> {}\r\n\r\nclass R<T> {\r\n  @AlwaysInline\r\n  R(T field);\r\n}\r\n\r\nclass C extends B {}\r\n\r\nclass D extends C {}\r\n\r\n// Method A<T>.m will be inlined and T=B will be forwarded to AssertAssignable in the\r\n// R. However B will be wrapped in the TypeRef which breaks runtime TypeCheck\r\n// function (Instance::IsInstanceOf does not work for TypeRefs).\r\n@NeverInline\r\nf(o) => new B().m(o);\r\n\r\nmain() {\r\n  final o = new D();\r\n  for (var i = 0; i < 10; i++) {\r\n    f(o);\r\n  }\r\n}\r\n```\r\n\r\n```\r\n$ out/DebugIA32/dart --enable_asserts --enable_type_checks --enable-inlining-annotations --optimization-counter-threshold=10 test.dart\r\nUnhandled exception:\r\ntype 'D' is not a subtype of type 'B' of 'field'.\r\n#0      R.R (file:///usr/local/google/home/vegorov/src/dart/sdk/test.dart:16:7)\r\n#1      A.m (file:///usr/local/google/home/vegorov/src/dart/sdk/test.dart:9:15)\r\n#2      f (file:///usr/local/google/home/vegorov/src/dart/sdk/test.dart:27:17)\r\n#3      main (file:///usr/local/google/home/vegorov/src/dart/sdk/test.dart:32:5)\r\n#4      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:261)\r\n#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)\r\n```\r\n"}}