New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong static type for caught errors #11682
Comments
Perhaps I'm reading the specification incorrectly, but section 13.11 says An on-catch clause of the form "catch (p) s" is equivalent to an an on-catch clause "on Object catch (p) s". and An on-catch clause of the form "on T catch (p1) s" is equivalent to an on-catch clause "on T catch (p1, p2) s", Therefore, I believe that when you wrote } catch(e2) { it is equivalent to } on Object catch(e2, s2) { In the same section, the specification later states that Execution of an on-catch clause "on T catch (p1, p2) s" of a try statement t proceeds as follows: Variables p1 of static type T, and p2 of static type StackTrace are implicitly declared, with a scope comprising s. It sounds to me like the static type of "e2" should therefore be "Object", not "dynamic". I think that in order to get the semantics you expect you'd have to write } on dynamic catch (e2) { If you disagree, please re-open the issue. Set owner to @bwilkerson. |
Filed issue #11683. |
Set owner to @stereotype441. |
I just wrote a unit test that tested that static initialization throws, and the analyzer assigned "Object" to static type of the caught type. It should have been dynamic.
As a workaround I assign the caught exception to a "var" now.
tests/corelib/error_stack_trace2_test.dart:
===
import "package:expect/expect.dart";
class A {
get foo => cyclicStatic;
}
var a = new A();
var cyclicStatic = (() => a.foo + 1)();
cyclicInitialization() {
return cyclicStatic;
}
main() {
bool hasThrown = false;
try {
cyclicStatic + 1;
} catch(e2) {
// Work around bug in analyzer that assigns "Object" type to caught error.
var e = e2;
hasThrown = true;
Expect.isTrue(e.stackTrace is StackTrace,
"$e doesn't have a non-null stack trace");
}
Expect.isTrue(hasThrown);
}
===
The text was updated successfully, but these errors were encountered: