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

Unrelated operator overloading causes incorrect exceptions #597

Closed
dgrove opened this issue Nov 24, 2011 · 4 comments
Closed

Unrelated operator overloading causes incorrect exceptions #597

dgrove opened this issue Nov 24, 2011 · 4 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue web-dart2js

Comments

@dgrove
Copy link
Contributor

dgrove commented Nov 24, 2011

svn r1844

(related to issue #576 and issue #596)

class x {
  operator+(x) => 1;
}

foo() => -1;

main() {
  print(foo() + "bar");
}

running frogsh on this produces:

TypeError: Object -1 has no method '$add'
    at $add (evalmachine.<anonymous>:6:17)
    at main (evalmachine.<anonymous>:36:9)
    at evalmachine.<anonymous>:38:1
    at main (/Users/dgrove/repo/dart-bleeding/dart/frog/frogsh:23536:10)
    at Object.<anonymous> (/Users/dgrove/repo/dart-bleeding/dart/frog/frogsh:23918:1)
    at Module._compile (module.js:411:26)
    at Object..js (module.js:417:10)
    at Module.load (module.js:343:31)
    at Function._load (module.js:302:12)
    at Array.<anonymous> (module.js:430:10)

this problem occurs with other operators, as well - if you overload them and then use the operator invalidly, you'll get the wrong sort of exception.

the VM produces:

NoSuchMethodException - receiver: 'bar' function name: 'addFromInteger' arguments: [-1]]
 0. Function: 'Object.noSuchMethod' url: 'bootstrap' line:315 col:3
 1. Function: 'IntegerImplementation.+' url: 'bootstrap_impl' line:1463 col:32
 2. Function: '::.main' url: '/Users/dgrove/repo/dart-bleeding/dart/frog/y.dart' line:8 col:15

@rakudrama
Copy link
Member

The stack traces are misleading. Node.js is reporting a JavaScript exception that has not been translated to a Dart exception. There is a comment:
    // TODO(jmesserly): setting the stack property is not a long term solution.
    // Also it causes the exception to print as if it were a JS TypeError or
    // RangeError, instead of using the proper toString.

You need to catch and print the exception to see what the type is from the view of the Dart program.
Issue #470 will make this difficult, but you can verify the type with (ex is NoSuchMethodException).
If you catch and re-throw, Node still seems to report the original exception for the reason above.

Translating the exceptions is hacky and JS implementation specific. It might be more portable to put O(methodNames) stubs on Object.

Question: is the VM exhibiting definitive behaviour?
It looks like it is throwing a NSME because of an implementation detail and I could imagine the runtime library throwing some other exception.

Or is addFromInteger part of the exported library?
(I can see that my class Polynomial might want to play with the regular number hierarchy but I am having more difficulty seeing how my Polynomial might have Complex coefficients.)
If so, must Frog fake the same receiver, method name, arguments?

@rakudrama
Copy link
Member

Provided you catch and re-throw the exception, http://codereview.chromium.org/8694007/ makes the correct message appear.

@anders-sandholm
Copy link
Contributor

Removed Area-Frog label.
Added Area-Dart2JS, FromAreaFrog labels.

@kasperl
Copy link

kasperl commented Jun 12, 2012

Added WontFix label.

@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue and removed resolution-wont_fix labels Mar 1, 2016
copybara-service bot pushed a commit that referenced this issue May 20, 2022
Changes:
```
> git log --format="%C(auto) %h %s" c1eb6cb..b149f80
 https://dart.googlesource.com/protobuf.git/+/b149f80 Remove the top level analysis_options.yaml file (#656)
 https://dart.googlesource.com/protobuf.git/+/8f6f307 Fix comment syntax
 https://dart.googlesource.com/protobuf.git/+/665f7b0 Remove trailing whitespace in protobuf/LICENSE
 https://dart.googlesource.com/protobuf.git/+/9ffbaf2 Fix default list type for frozen messages (#654)
 https://dart.googlesource.com/protobuf.git/+/a68bb5a Fix Fixed32 to be parsed as unsigned when parsing proto3 protos (#655)
 https://dart.googlesource.com/protobuf.git/+/6957c98 Convert the field started with underscore and digit to a legal name (#651)
 https://dart.googlesource.com/protobuf.git/+/71defca Account for double.infinity and double.nan in json serializers (#652)
 https://dart.googlesource.com/protobuf.git/+/5a48349 Allow `Timestamp.toDateTime()` to return a `DateTime` in local timezone (#653)
 https://dart.googlesource.com/protobuf.git/+/117e869 Make the toString of enums be the value if names are omitted (#649)
 https://dart.googlesource.com/protobuf.git/+/88c4016 Align the hashCode of a message with an empty unknown field-set with that of no unknown field set (#648)
 https://dart.googlesource.com/protobuf.git/+/eed09c4 Fix proto3 repeated field encoding without packed option (#635)
 https://dart.googlesource.com/protobuf.git/+/8f587b1 Simplify `_FieldSet` getters (#646)
 https://dart.googlesource.com/protobuf.git/+/494f189 Fix compile-protos.sh interpreter (#645)
 https://dart.googlesource.com/protobuf.git/+/5e1a422 Fix typo in protobuf-0.9.0+1 changelog
 https://dart.googlesource.com/protobuf.git/+/46df68a Add `UseResult` annotation to `rebuild` (#631)
 https://dart.googlesource.com/protobuf.git/+/ff5304f Migrate protoc_plugin to null safety (#642)
 https://dart.googlesource.com/protobuf.git/+/657197d Fix typo in GeneratedMessage.copyWith documentation (#641)
 https://dart.googlesource.com/protobuf.git/+/e30a522 Fix sharing coded buffer bytes when parsing `bytes` fields (#640)
 https://dart.googlesource.com/protobuf.git/+/810b166 Clear unknown field when setting an extension field with the same tag (#639)
 https://dart.googlesource.com/protobuf.git/+/d30623b Treat empty and uninitialized Maps the same in equality checks (#638)
 https://dart.googlesource.com/protobuf.git/+/4fe3ee4 Make `MapFieldInfo` key and value types non-nullable (#600)
 https://dart.googlesource.com/protobuf.git/+/c26ac34 Add grpc example to protoc_plugin README (#514)
 https://dart.googlesource.com/protobuf.git/+/c35d787 Revert changes to reserved names to maintain backwards compat (#636)
 https://dart.googlesource.com/protobuf.git/+/146b186 Remove unused `GeneratedMessage` constructors (#634)
 https://dart.googlesource.com/protobuf.git/+/1b12ac9 Remove a closure in `_FieldSet.hashCode` (#633)
 https://dart.googlesource.com/protobuf.git/+/5731242 Minor fix in query_bench set_nested_value benchmark: (#630)
 https://dart.googlesource.com/protobuf.git/+/767ce81 Remove fold() closures from `FieldSet._hashCode`. (#554)
 https://dart.googlesource.com/protobuf.git/+/99bc541 protoc_plugin README fixes and tweaks: (#617)
 https://dart.googlesource.com/protobuf.git/+/e282e17 protobuf benchs: invoke protoc once with all protos (#623)
 https://dart.googlesource.com/protobuf.git/+/bef672b protobuf benchs: fix old --trust-type-annotations flag (#622)
 https://dart.googlesource.com/protobuf.git/+/d072e5f dependabot: check for updates monthly (#620)
 https://dart.googlesource.com/protobuf.git/+/96bdf38 Fix TypeRegistry passing when unpacking nested Any messages from JSON (#568)
 https://dart.googlesource.com/protobuf.git/+/4ec722a Correctly combine hash codes for repeated enums. (#556)
 https://dart.googlesource.com/protobuf.git/+/b96dc21 Testing: don't return static methods in findMemberNames (#618)
 https://dart.googlesource.com/protobuf.git/+/09e8a8d Update protobuf/benchmarks README for #553
 https://dart.googlesource.com/protobuf.git/+/3ef4539 Add a benchmark for computing hashCodes. (#553)
 https://dart.googlesource.com/protobuf.git/+/d232e6e Tweak READMEs: (#610)
 https://dart.googlesource.com/protobuf.git/+/0f01fa9 Update protobuf pubspec.yaml (#616)
 https://dart.googlesource.com/protobuf.git/+/a10426b Update protoc_plugin pubspec.yaml (#615)
 https://dart.googlesource.com/protobuf.git/+/a0021c7 Make `protoName` unCamelCase lazy (#606)
 https://dart.googlesource.com/protobuf.git/+/ded1ac7 Document map key and value fields (#603)
 https://dart.googlesource.com/protobuf.git/+/8792f2a Remove redundant check in PbMap equality check (#604)
 https://dart.googlesource.com/protobuf.git/+/b7f9569 Tweak BuilderInfo and FieldInfo docs: (#597)
 https://dart.googlesource.com/protobuf.git/+/6f85c32 Remove a redundant cast (#598)
 https://dart.googlesource.com/protobuf.git/+/3df8669 Latest mono_repo (#601)
 https://dart.googlesource.com/protobuf.git/+/9da84ae Fix a potential issue in CodedBufferWriter (#594)
 https://dart.googlesource.com/protobuf.git/+/6be405f Remove old and unused test file (#589)
 https://dart.googlesource.com/protobuf.git/+/900cef5 Fix protoc_plugin run-tests make rule (#586)
 https://dart.googlesource.com/protobuf.git/+/2546269 Fix rounding when handling negative timestamps (#580)
 https://dart.googlesource.com/protobuf.git/+/8afce8d Fix Readme `pub get` instead of `pub install`. (#486)
 https://dart.googlesource.com/protobuf.git/+/782fd24 Avoid runtime function type check in lazily created singleton creator functions (#574)
 https://dart.googlesource.com/protobuf.git/+/a7e75cb Update README.md
 https://dart.googlesource.com/protobuf.git/+/23136dc Version bump (#563)
 https://dart.googlesource.com/protobuf.git/+/18346f5 Convert null keys and values to default when parsing map entries (#536)
 https://dart.googlesource.com/protobuf.git/+/bb4cf0b Bump to latest mono_repo - use latest actions (#561)
 https://dart.googlesource.com/protobuf.git/+/835ab75 Remove unneeded imports
 https://dart.googlesource.com/protobuf.git/+/ef733ac latest mono_repo
 https://dart.googlesource.com/protobuf.git/+/ecfb862 Fix test for latest analysis (#543)
 https://dart.googlesource.com/protobuf.git/+/26a0a26 fix insecure link in protoc_plugin readme
 https://dart.googlesource.com/protobuf.git/+/444e855 Bump dart-lang/setup-dart from 1.1 to 1.2 (#535)
 https://dart.googlesource.com/protobuf.git/+/d3e0e4a Fix analysis options
 https://dart.googlesource.com/protobuf.git/+/cf29280 Fix comment references

```

Diff: https://dart.googlesource.com/protobuf.git/+/c1eb6cb51af39ccbaa1a8e19349546586a5c8e31~..b149f801cf7a5e959cf1dbf72d61068ac275f24b/

Tested: relying on existing SDK and protobuf tests
Change-Id: I7f89b998a0aba13999d180ee9814a26a5f1d054d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245228
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
copybara-service bot pushed a commit that referenced this issue May 12, 2023
…er, mime, mockito, native, path, test, watcher, webdev, yaml_edit

Revisions updated by `dart tools/rev_sdk_deps.dart`.

browser_launcher (https://github.com/dart-lang/browser_launcher/compare/ed11524..551e101):
  551e101  2023-05-11  dependabot[bot]  Bump actions/checkout from 3.5.0 to 3.5.2 (#43)
  29a57a0  2023-05-11  Elliott Brooks  Disable test (#44)

file (https://github.com/google/file.dart/compare/b905180..e90e5ed):
  e90e5ed  2023-05-11  Bernardo Ferrari  Migrate to Dart 3 (#210)

http (https://github.com/dart-lang/http/compare/db84d12..981b63b):
  981b63b  2023-05-11  Brian Quinlan  Support the NSURLSession WebSocket API (#921)

leak_tracker (https://github.com/dart-lang/leak_tracker/compare/46a1fa0..bc7f604):
  bc7f604  2023-05-11  Polina Cherkasova  Fix typo. (#61)

logging (https://github.com/dart-lang/logging/compare/4779d7e..b75cba7):
  b75cba7  2023-05-10  Devon Carew  blast_repo fixes (#137)

matcher (https://github.com/dart-lang/matcher/compare/5890f2b..4dfd9ad):
  4dfd9ad  2023-05-10  dependabot[bot]  Bump actions/checkout from 3.5.0 to 3.5.2 (#218)

mime (https://github.com/dart-lang/mime/compare/57fbf6e..eb9d54b):
  eb9d54b  2023-05-10  Devon Carew  blast_repo fixes (#95)

mockito (https://github.com/dart-lang/mockito/compare/56173fa..51a7728):
  51a7728  2023-05-12  Copybara-Service  Merge pull request #597 from danielgomezrico:feat/returnInOrder
  7a93b61  2023-01-15  Daniel Gomez Rico  Add `returnInOrder` to `Mock`
  34da8da  2023-05-02  Nate Bosch  Import `packge:matcher` directly instead of `test_api`

native (https://github.com/dart-lang/native/compare/908e61f..64aa5b5):
  64aa5b5  2023-05-12  Daco Harkes  [native_assets_cli] Add `outDirName` (#38)
  fdcd0eb  2023-05-09  Devon Carew  contribute a PR labeler (#37)
  d44eae5  2023-05-08  Daco Harkes  Give tests on MacOS more time (#36)
  3b39e07  2023-05-04  Daco Harkes  [c_compiler] Make `logger` required (#35)

path (https://github.com/dart-lang/path/compare/1552cfd..f8d15c2):
  f8d15c2  2023-05-10  Devon Carew  blast_repo fixes (#144)

test (https://github.com/dart-lang/test/compare/0b306dd..931410c):
  931410c8  2023-05-10  Nate Bosch  Fix CI (#2014)

watcher (https://github.com/dart-lang/watcher/compare/9430592..1584936):
  1584936  2023-05-12  Brian Quinlan  Update to 1.1.0 in preparation for release. (#145)

webdev (https://github.com/dart-lang/webdev/compare/469b105..60616ba):
  60616bac  2023-05-10  Elliott Brooks  Syntax error in DCM workflow file(#2108)

yaml_edit (https://github.com/dart-lang/yaml_edit/compare/763ca94..87dcf31):
  87dcf31  2023-05-10  Devon Carew  blast_repo fixes (#53)

Change-Id: I4d25e4ccb60a86a6b5f8a66cfc6ae09f6df0a954
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303005
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue web-dart2js
Projects
None yet
Development

No branches or pull requests

5 participants