Skip to content
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

Closed
floitschG opened this issue Jul 3, 2013 · 5 comments
Closed

Wrong static type for caught errors #11682

floitschG opened this issue Jul 3, 2013 · 5 comments
Assignees
Labels
area-analyzer closed-duplicate Closed in favor of an existing report

Comments

@floitschG
Copy link
Contributor

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);
}
===

@bwilkerson
Copy link
Member

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",
    where "p2" is an identifier that does not occur anywhere else in the program.

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.
Added this to the M6 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium, AsDesigned labels.

@floitschG
Copy link
Contributor Author

Filed issue #11683.

@floitschG
Copy link
Contributor Author

Reopening since the spec was updated.


Removed this from the M6 milestone.
Added Triaged label.

@stereotype441
Copy link
Member

Set owner to @stereotype441.
Added Started label.

@stereotype441
Copy link
Member

This was fixed in revision 28907.


Added Duplicate label.
Marked as being merged into #14028.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

3 participants