Giter Club home page Giter Club logo

Comments (8)

sync-by-unito avatar sync-by-unito commented on September 24, 2024

➤ PM Bot commented:

Jira ticket: RDART-992

from realm-dart.

Bilonik avatar Bilonik commented on September 24, 2024

Hi,

Same issue here, any workaround?

from realm-dart.

nirinchev avatar nirinchev commented on September 24, 2024

We're aware of this and will address it with a future release. Currently, the only known mitigation is to downgrade to 1.6. I'm sorry for the regression.

from realm-dart.

nielsenko avatar nielsenko commented on September 24, 2024

Apparently -1 is not a literal to the Dart analyzer

from realm-dart.

derrickgw avatar derrickgw commented on September 24, 2024

from realm-dart.

derrickgw avatar derrickgw commented on September 24, 2024

That looks like a great improvement. Unfortunately there are still some cases that cause false errors. Here is an example:

import 'package:dart_numerics/dart_numerics.dart' as numerics;
const int myconst = 1;
@RealmModel(ObjectType.embeddedObject)
class $Test {
  ObjectId id = ObjectId();
  int value1 = myconst;
  int value2 = numerics.int64MinValue;
}

If I comment out the new const test, this generates legal dart.

from realm-dart.

nielsenko avatar nielsenko commented on September 24, 2024

@derrickgw Thank you for your observation. I have created #1612 to handle value1 and value2.

But this const check was added explicitly to disallow ObjectId id = ObjectId(), so that is still not allowed.

Consider:

@RealmModel()
class _Stuff {
  ObjectId id = ObjectId();
}

Which is legal with realm_generator 1.9.0. If you look at the generated class, you will find that is illegal because it lifts the initializer expression and uses it as the default value of the optional parameter id on the generated constructor.

Stuff({
    ObjectId id = ObjectId(), // <-- this is not valid Dart, as default values must be const
  }) {

from realm-dart.

derrickgw avatar derrickgw commented on September 24, 2024

Wow. That was super fast. Thanks.

I see now that ObjectId has a constructor body, and calls DateTime.now(), so it can't really become a const class.

The previous database code generator I migrated from had a different paradigm that generated a Schema class instead of a child class, which allowed non-const default values, but had other limitations.

from realm-dart.

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.