Coder Social home page Coder Social logo

Comments (4)

navaronbracke avatar navaronbracke commented on July 3, 2024

I believe this is working as intended.

If you change

  final Map<String,dynamic> test = Map.from( {
      "value1": 1,
      "value2": "1"
  });

to use Object? instead of dynamic, you should get a type error.

  final Map<String, Object?> test = Map.from( {
      "value1": 1,
      "value2": "1"
  });

When you use dynamic, type checks are omitted, so the assignment to int value2 = test['value2']; is actually unchecked.

from sdk.

hugovangalen avatar hugovangalen commented on July 3, 2024

When you use dynamic, type checks are omitted, so the assignment to int value2 = test['value2']; is actually unchecked.

Interesting. This isn't unchecked on native. Are you implying that the problem lies in the native runtime?

This for example throws an RTE on native (Linux command line) yet no RTE on web:

    dynamic string3 = "3";
    int value3 = string3;

Regardless, it is inconsistent. I believe the exception should happen either in both, or in neither.

(Also, it appears my title for this bug is incorrect as I now realise this doesn't affect Maps. It boils down to "Inconsistent runtime behaviour with dynamic type on web and native" and I will update that accordingly.)

from sdk.

mraleph avatar mraleph commented on July 3, 2024

This is working as intended: dart2js compiler omits implicit type checks at -O3 optimization level or above. (and dart2wasm even omits explicit type checks). Native compilers never omit type checks.

So you need to write all your type checks explicitly if you don't want them to be omitted (e.g. if they are validating input data from JSON).

from sdk.

hugovangalen avatar hugovangalen commented on July 3, 2024

Okay thanks for clearing that up!

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.