Coder Social home page Coder Social logo

Comments (2)

eernstg avatar eernstg commented on May 23, 2024

This might be the case with DDC as well.

from sdk.

lrhn avatar lrhn commented on May 23, 2024

It's even more weird. The symbols are not equal, but they are identical.

void main() {
  const s1 = #_foo;
  const s2 = Symbol("_foo");
  print(s1 == s2); // false
  print(identical(s1, s2)); // true
}

The two objects are identical. (Also when not checked as constants, not even knowing that identical is the function being called):

  var id = DateTime.now().millisecondsSinceEpoch > 0 ? identical : (a, b) => Math.random().nextBool();
  print("id: ${id(s1, s2)}"); // True.                             

This still prints true, so it is the runtime check saying so.

On the other hand, a constant evaluation behaves correctly:

const ceq = s1 == s2;
const cid = identical(s1, s2);
print(ceq); // false
print(cid); // false

which means the front-end constant evaluation behavior is correct, but Dart2js, and probably DDC, both behave inconsistently.
(It's not even reflexive! Equality, you had one job! Well three, but this is the first one!)

(Interestingly, the analyzer is also wrong:

void main() {
  const s1 = #_foo;
  const s2 = Symbol("_foo");
  const Chk.neq(s1, s2); // Analyer: Error
  const Chk.nid(s1, s2); // Analyer: Error
  const Chk.eq(s1, s2); // Analyer: OK
  const Chk.id(s1, s2); // Analyer: OK
}

class Chk {
  const Chk.eq(Object? v1, Object? v2) : assert((v1 == v2), "eq failed");
  const Chk.id(Object? v1, Object? v2) : assert(identical(v1, v2), "id failed");
  const Chk.neq(Object? v1, Object? v2) : assert(!(v1 == v2), "neq failed");
  const Chk.nid(Object? v1, Object? v2)
      : assert(!identical(v1, v2), "nid failed");
}

The failures should be on the eq/id invocations instead.

The VM's only failure seems to be #_foo.bar which it treats as "library private", even if all library names should be unaffected by privacy.)

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.