Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Issue 390003002: Fix crash bug with noSuchMethod invocation and argument count mismatch. (Closed)

Created:
6 years, 5 months ago by Florian Schneider
Modified:
6 years, 5 months ago
Reviewers:
regis, Ivan Posva
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Visibility:
Public.

Description

Fix crash bug with noSuchMethod invocation and argument count mismatch. When trying to invoke noSuchMethod on an object and it does not implement noSuchMethod(i) -- with one argument, but with a mismatching number of arguments, throw a NoSuchMethodError. BUG=dartbug.com/12561 TEST=tests/language/regress_12561_test.dart R=iposva@google.com Committed: https://code.google.com/p/dart/source/detail?r=38183

Patch Set 1 #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+29 lines, -3 lines) Patch
M runtime/vm/parser.cc View 1 chunk +14 lines, -3 lines 2 comments Download
A tests/language/regress_12561_test.dart View 1 chunk +15 lines, -0 lines 0 comments Download

Messages

Total messages: 9 (0 generated)
Florian Schneider
6 years, 5 months ago (2014-07-14 09:55:58 UTC) #1
Ivan Posva
LGTMwC -ip https://codereview.chromium.org/390003002/diff/1/runtime/vm/parser.cc File runtime/vm/parser.cc (right): https://codereview.chromium.org/390003002/diff/1/runtime/vm/parser.cc#newcode1389 runtime/vm/parser.cc:1389: no_such_method ^= Resolver::ResolveDynamicForReceiverClass( Indentation.
6 years, 5 months ago (2014-07-14 10:03:19 UTC) #2
Florian Schneider
https://codereview.chromium.org/390003002/diff/1/runtime/vm/parser.cc File runtime/vm/parser.cc (right): https://codereview.chromium.org/390003002/diff/1/runtime/vm/parser.cc#newcode1389 runtime/vm/parser.cc:1389: no_such_method ^= Resolver::ResolveDynamicForReceiverClass( On 2014/07/14 10:03:19, Ivan Posva wrote: ...
6 years, 5 months ago (2014-07-14 10:06:20 UTC) #3
Florian Schneider
Committed patchset #1 manually as r38183 (presubmit successful).
6 years, 5 months ago (2014-07-14 10:06:48 UTC) #4
regis
If I modify the regression test as below, I get a NoSuchMethodError. Is that expected? ...
6 years, 5 months ago (2014-07-14 17:40:18 UTC) #5
Ivan Posva
On 2014/07/14 17:40:18, regis wrote: > If I modify the regression test as below, I ...
6 years, 5 months ago (2014-07-14 20:04:38 UTC) #6
regis
On 2014/07/14 20:04:38, Ivan Posva wrote: > On 2014/07/14 17:40:18, regis wrote: > > If ...
6 years, 5 months ago (2014-07-14 20:30:14 UTC) #7
regis
On 2014/07/14 20:30:14, regis wrote: > On 2014/07/14 20:04:38, Ivan Posva wrote: > > On ...
6 years, 5 months ago (2014-07-14 20:32:08 UTC) #8
regis
6 years, 5 months ago (2014-07-14 22:00:24 UTC) #9
Message was sent while issue was closed.
On 2014/07/14 20:32:08, regis wrote:
> On 2014/07/14 20:30:14, regis wrote:
> > On 2014/07/14 20:04:38, Ivan Posva wrote:
> > > On 2014/07/14 17:40:18, regis wrote:
> > > > If I modify the regression test as below, I get a NoSuchMethodError. Is
> that
> > > > expected? I would think the noSuchMethod of the base class should be
> called.
> > > > 
> > > > class B {
> > > >   noSuchMethod(Invocation m) => 42;
> > > > }
> > > > 
> > > > class C extends B {
> > > >   noSuchMethod(int x, int y) => x + y;
> > > > }
> > > > 
> > > > main() {
> > > >   Expect.equals(42, new B().foo);  // OK
> > > >   Expect.equals(42, new C().foo);  // NoSuchMethodError
> > > > }
> > > 
> > > We dispatch to the noSuchMethod of the receiver. Since that one is
incorrect
> > > (wrong number of parameters) we throw a noSuchMethodError, which is the
> > correct
> > > behaviour. noSuchMethod lookup is just like any regular method lookup. If
> you
> > > had declared method foo in B and C and the number of parameters did not
> match
> > > when calling C, you'd not attempt to resolve in B either.
> > > 
> > > -Ivan
> > 
> > I stand corrected. My impression was that noSuchMethod should be called in
> case
> > the number of actual and formal parameters do not match. But this is wrong,
> > noSuchMethod is thrown in this case, which is consistent with the fix.
> 
> Argh! I meant: "noSuchMethodError is thrown in this case"

Let me clarify. The fact that foo is invoked without parenthesis is important.
It means that we invoke a function and not a method.

A function invocation with the wrong number of arguments results in a
noSuchMethodError being thrown, as Ivan says.
However, a method invocation with the wrong number of arguments results in a
call to noSuchMethod and it was the point I tried to make in my original
comment, but I did not write it correctly (missing parenthesis).

This test succeeds:

class B {
   noSuchMethod(Invocation m) => 42;
}

class C extends B {
   foo(int x, int y) => x + y;
}

main() {
   Expect.equals(42, new C().foo());
}

Therefore, I was expecting this test to succeed as well (note the parenthesis
after foo):

class B {
   noSuchMethod(Invocation m) => 42;
}

class C extends B {
   noSuchMethod(int x, int y) => x + y;
}

main() {
   Expect.equals(42, new C().foo());
}


But it does not, because of Gilad's spec change. Florian's fix matches the
revised spec. However, the implementation is still not quite correct, because
memberName of Invocation should be "noSuchMethod" and not "foo".

Also, this test still crashes with a stack overflow:

class C {
  noSuchMethod(im) => x + y;
}

main() {
  new C().foo;
}

Powered by Google App Engine
This is Rietveld 408576698