From cd48882879662cfb70c3bc211765e5bfbb152260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 27 Mar 2024 11:51:44 +0100 Subject: [PATCH 1/5] Const initializer evaluation is too simple --- .../lib/src/field_element_ex.dart | 9 +- .../good_test_data/const_initializer.dart | 20 ++ .../good_test_data/const_initializer.expected | 177 ++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 packages/realm_generator/test/good_test_data/const_initializer.dart create mode 100644 packages/realm_generator/test/good_test_data/const_initializer.expected diff --git a/packages/realm_generator/lib/src/field_element_ex.dart b/packages/realm_generator/lib/src/field_element_ex.dart index d7f001262..508286982 100644 --- a/packages/realm_generator/lib/src/field_element_ex.dart +++ b/packages/realm_generator/lib/src/field_element_ex.dart @@ -347,7 +347,7 @@ extension FieldElementEx on FieldElement { } final initExpression = initializerExpression; - if (initExpression != null && initExpression is! Literal) { + if (initExpression != null && !_isValidFieldInitializer(initExpression)) { throw RealmInvalidGenerationSourceError( 'Field initializers must be constant', primarySpan: initializerExpressionSpan(file, initExpression), @@ -390,4 +390,11 @@ extension FieldElementEx on FieldElement { } return false; } + + bool _isValidFieldInitializer(Expression initExpression) { + if (initExpression is Literal) return true; + if (initExpression is InstanceCreationExpression) return initExpression.isConst; + if (initExpression is PrefixExpression) return _isValidFieldInitializer(initExpression.operand); + return false; + } } diff --git a/packages/realm_generator/test/good_test_data/const_initializer.dart b/packages/realm_generator/test/good_test_data/const_initializer.dart new file mode 100644 index 000000000..6206d80ce --- /dev/null +++ b/packages/realm_generator/test/good_test_data/const_initializer.dart @@ -0,0 +1,20 @@ +import 'package:realm_common/realm_common.dart'; + +part 'const_initializer.realm.dart'; + +@RealmModel() +class _ConstInitizers { + int x = 0; + int y = -1; + int z = const int.fromEnvironment('FOO', defaultValue: 1); + + String a = const String.fromEnvironment('FOO'); + String b = 'foo'; + + var s = const []; // list + var t = const {}; // map + var u = const {}; // set + + var v = []; + var w = {}; +} diff --git a/packages/realm_generator/test/good_test_data/const_initializer.expected b/packages/realm_generator/test/good_test_data/const_initializer.expected new file mode 100644 index 000000000..56c785016 --- /dev/null +++ b/packages/realm_generator/test/good_test_data/const_initializer.expected @@ -0,0 +1,177 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'const_initializer.dart'; + +// ************************************************************************** +// RealmObjectGenerator +// ************************************************************************** + +// ignore_for_file: type=lint +class ConstInitizers extends _ConstInitizers + with RealmEntity, RealmObjectBase, RealmObject { + static var _defaultsSet = false; + + ConstInitizers({ + int x = 0, + int y = -1, + int z = const int.fromEnvironment('FOO', defaultValue: 1), + String a = const String.fromEnvironment('FOO'), + String b = 'foo', + Iterable s = const [], + Map t = const {}, + Set u = const {}, + Iterable v = const [], + Map w = const {}, + }) { + if (!_defaultsSet) { + _defaultsSet = RealmObjectBase.setDefaults({ + 'x': 0, + 'y': -1, + 'z': const int.fromEnvironment('FOO', defaultValue: 1), + 'a': const String.fromEnvironment('FOO'), + 'b': 'foo', + }); + } + RealmObjectBase.set(this, 'x', x); + RealmObjectBase.set(this, 'y', y); + RealmObjectBase.set(this, 'z', z); + RealmObjectBase.set(this, 'a', a); + RealmObjectBase.set(this, 'b', b); + RealmObjectBase.set>(this, 's', RealmList(s)); + RealmObjectBase.set>(this, 't', RealmMap(t)); + RealmObjectBase.set>(this, 'u', RealmSet(u)); + RealmObjectBase.set>(this, 'v', RealmList(v)); + RealmObjectBase.set>(this, 'w', RealmMap(w)); + } + + ConstInitizers._(); + + @override + int get x => RealmObjectBase.get(this, 'x') as int; + @override + set x(int value) => RealmObjectBase.set(this, 'x', value); + + @override + int get y => RealmObjectBase.get(this, 'y') as int; + @override + set y(int value) => RealmObjectBase.set(this, 'y', value); + + @override + int get z => RealmObjectBase.get(this, 'z') as int; + @override + set z(int value) => RealmObjectBase.set(this, 'z', value); + + @override + String get a => RealmObjectBase.get(this, 'a') as String; + @override + set a(String value) => RealmObjectBase.set(this, 'a', value); + + @override + String get b => RealmObjectBase.get(this, 'b') as String; + @override + set b(String value) => RealmObjectBase.set(this, 'b', value); + + @override + RealmList get s => RealmObjectBase.get(this, 's') as RealmList; + @override + set s(covariant RealmList value) => throw RealmUnsupportedSetError(); + + @override + RealmMap get t => RealmObjectBase.get(this, 't') as RealmMap; + @override + set t(covariant RealmMap value) => throw RealmUnsupportedSetError(); + + @override + RealmSet get u => RealmObjectBase.get(this, 'u') as RealmSet; + @override + set u(covariant RealmSet value) => throw RealmUnsupportedSetError(); + + @override + RealmList get v => RealmObjectBase.get(this, 'v') as RealmList; + @override + set v(covariant RealmList value) => throw RealmUnsupportedSetError(); + + @override + RealmMap get w => RealmObjectBase.get(this, 'w') as RealmMap; + @override + set w(covariant RealmMap value) => throw RealmUnsupportedSetError(); + + @override + Stream> get changes => + RealmObjectBase.getChanges(this); + + @override + ConstInitizers freeze() => RealmObjectBase.freezeObject(this); + + EJsonValue toEJson() { + return { + 'x': x.toEJson(), + 'y': y.toEJson(), + 'z': z.toEJson(), + 'a': a.toEJson(), + 'b': b.toEJson(), + 's': s.toEJson(), + 't': t.toEJson(), + 'u': u.toEJson(), + 'v': v.toEJson(), + 'w': w.toEJson(), + }; + } + + static EJsonValue _toEJson(ConstInitizers value) => value.toEJson(); + static ConstInitizers _fromEJson(EJsonValue ejson) { + return switch (ejson) { + { + 'x': EJsonValue x, + 'y': EJsonValue y, + 'z': EJsonValue z, + 'a': EJsonValue a, + 'b': EJsonValue b, + 's': EJsonValue s, + 't': EJsonValue t, + 'u': EJsonValue u, + 'v': EJsonValue v, + 'w': EJsonValue w, + } => + ConstInitizers( + x: fromEJson(x), + y: fromEJson(y), + z: fromEJson(z), + a: fromEJson(a), + b: fromEJson(b), + s: fromEJson(s), + t: fromEJson(t), + u: fromEJson(u), + v: fromEJson(v), + w: fromEJson(w), + ), + _ => raiseInvalidEJson(ejson), + }; + } + + static final schema = () { + RealmObjectBase.registerFactory(ConstInitizers._); + register(_toEJson, _fromEJson); + return SchemaObject( + ObjectType.realmObject, ConstInitizers, 'ConstInitizers', [ + SchemaProperty('x', RealmPropertyType.int), + SchemaProperty('y', RealmPropertyType.int), + SchemaProperty('z', RealmPropertyType.int), + SchemaProperty('a', RealmPropertyType.string), + SchemaProperty('b', RealmPropertyType.string), + SchemaProperty('s', RealmPropertyType.int, + collectionType: RealmCollectionType.list), + SchemaProperty('t', RealmPropertyType.int, + collectionType: RealmCollectionType.map), + SchemaProperty('u', RealmPropertyType.int, + collectionType: RealmCollectionType.set), + SchemaProperty('v', RealmPropertyType.int, + collectionType: RealmCollectionType.list), + SchemaProperty('w', RealmPropertyType.int, + collectionType: RealmCollectionType.map), + ]); + }(); + + @override + SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; +} From 80096fc28e261d77988787ad6d6037eb38ad7c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Wed, 27 Mar 2024 11:57:06 +0100 Subject: [PATCH 2/5] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0dda54d..fb5fe5f20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Improve file compaction performance on platforms with page sizes greater than 4k (for example arm64 Apple platforms) for files less than 256 pages in size (Core 14.4.0). ### Fixed +* Using `-1` as an initializer would fail. ([#1606](https://github.com/realm/realm-dart/issues/1606)) ### Compatibility * Realm Studio: 13.0.0 or later. From 767292dfbd44f6fd984f59439e435ec0da532422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 28 Mar 2024 17:44:50 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com> --- CHANGELOG.md | 2 +- .../realm_generator/test/good_test_data/const_initializer.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb5fe5f20..3a8dacf23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * Improve file compaction performance on platforms with page sizes greater than 4k (for example arm64 Apple platforms) for files less than 256 pages in size (Core 14.4.0). ### Fixed -* Using `-1` as an initializer would fail. ([#1606](https://github.com/realm/realm-dart/issues/1606)) +* Using prefix expressions such as negation of numbers as an initializer would fail. (Issue [#1606](https://github.com/realm/realm-dart/issues/1606)) ### Compatibility * Realm Studio: 13.0.0 or later. diff --git a/packages/realm_generator/test/good_test_data/const_initializer.dart b/packages/realm_generator/test/good_test_data/const_initializer.dart index 6206d80ce..327437197 100644 --- a/packages/realm_generator/test/good_test_data/const_initializer.dart +++ b/packages/realm_generator/test/good_test_data/const_initializer.dart @@ -3,7 +3,7 @@ import 'package:realm_common/realm_common.dart'; part 'const_initializer.realm.dart'; @RealmModel() -class _ConstInitizers { +class _ConstInitializer { int x = 0; int y = -1; int z = const int.fromEnvironment('FOO', defaultValue: 1); From 54917a6624bb29aa0a367d6e64e52299f87061f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 28 Mar 2024 17:54:15 +0100 Subject: [PATCH 4/5] Handle, more complex cases --- .../lib/src/field_element_ex.dart | 12 +- .../good_test_data/const_initializer.dart | 26 +- .../good_test_data/const_initializer.expected | 263 +++++++++++------- 3 files changed, 190 insertions(+), 111 deletions(-) diff --git a/packages/realm_generator/lib/src/field_element_ex.dart b/packages/realm_generator/lib/src/field_element_ex.dart index 508286982..47bf95e3b 100644 --- a/packages/realm_generator/lib/src/field_element_ex.dart +++ b/packages/realm_generator/lib/src/field_element_ex.dart @@ -392,9 +392,13 @@ extension FieldElementEx on FieldElement { } bool _isValidFieldInitializer(Expression initExpression) { - if (initExpression is Literal) return true; - if (initExpression is InstanceCreationExpression) return initExpression.isConst; - if (initExpression is PrefixExpression) return _isValidFieldInitializer(initExpression.operand); - return false; + return switch (initExpression) { + Literal _ => true, + InstanceCreationExpression i => i.isConst, + ParenthesizedExpression i => _isValidFieldInitializer(i.expression), + PrefixExpression e => _isValidFieldInitializer(e.operand), + BinaryExpression b => _isValidFieldInitializer(b.leftOperand) && _isValidFieldInitializer(b.rightOperand), + _ => false, + }; } } diff --git a/packages/realm_generator/test/good_test_data/const_initializer.dart b/packages/realm_generator/test/good_test_data/const_initializer.dart index 327437197..2ce626738 100644 --- a/packages/realm_generator/test/good_test_data/const_initializer.dart +++ b/packages/realm_generator/test/good_test_data/const_initializer.dart @@ -4,17 +4,23 @@ part 'const_initializer.realm.dart'; @RealmModel() class _ConstInitializer { - int x = 0; - int y = -1; - int z = const int.fromEnvironment('FOO', defaultValue: 1); + int zero = 0; + int minusOne = -1; + int fooOrOne = const int.fromEnvironment('FOO', defaultValue: 1); + int parenthesis = (1); + int minusMinusOne = -(-1); + int add = 1 + 1; - String a = const String.fromEnvironment('FOO'); - String b = 'foo'; + String fooEnv = const String.fromEnvironment('FOO'); + String fooLit = 'foo'; - var s = const []; // list - var t = const {}; // map - var u = const {}; // set + // const collections allowed, but must be empty + var constEmptyList = const []; // list + var constEmptyMap = const {}; // map + var constEmptySet = const {}; // set - var v = []; - var w = {}; + // const not needed on collections + var emptyList = []; + var emptyMao = {}; + var emptySet = {}; } diff --git a/packages/realm_generator/test/good_test_data/const_initializer.expected b/packages/realm_generator/test/good_test_data/const_initializer.expected index 56c785016..9267acfd2 100644 --- a/packages/realm_generator/test/good_test_data/const_initializer.expected +++ b/packages/realm_generator/test/good_test_data/const_initializer.expected @@ -7,168 +7,237 @@ part of 'const_initializer.dart'; // ************************************************************************** // ignore_for_file: type=lint -class ConstInitizers extends _ConstInitizers +class ConstInitializer extends _ConstInitializer with RealmEntity, RealmObjectBase, RealmObject { static var _defaultsSet = false; - ConstInitizers({ - int x = 0, - int y = -1, - int z = const int.fromEnvironment('FOO', defaultValue: 1), - String a = const String.fromEnvironment('FOO'), - String b = 'foo', - Iterable s = const [], - Map t = const {}, - Set u = const {}, - Iterable v = const [], - Map w = const {}, + ConstInitializer({ + int zero = 0, + int minusOne = -1, + int fooOrOne = const int.fromEnvironment('FOO', defaultValue: 1), + int parenthesis = (1), + int minusMinusOne = -(-1), + int add = 1 + 1, + String fooEnv = const String.fromEnvironment('FOO'), + String fooLit = 'foo', + Iterable constEmptyList = const [], + Map constEmptyMap = const {}, + Set constEmptySet = const {}, + Iterable emptyList = const [], + Map emptyMao = const {}, + Set emptySet = const {}, }) { if (!_defaultsSet) { - _defaultsSet = RealmObjectBase.setDefaults({ - 'x': 0, - 'y': -1, - 'z': const int.fromEnvironment('FOO', defaultValue: 1), - 'a': const String.fromEnvironment('FOO'), - 'b': 'foo', + _defaultsSet = RealmObjectBase.setDefaults({ + 'zero': 0, + 'minusOne': -1, + 'fooOrOne': const int.fromEnvironment('FOO', defaultValue: 1), + 'parenthesis': (1), + 'minusMinusOne': -(-1), + 'add': 1 + 1, + 'fooEnv': const String.fromEnvironment('FOO'), + 'fooLit': 'foo', }); } - RealmObjectBase.set(this, 'x', x); - RealmObjectBase.set(this, 'y', y); - RealmObjectBase.set(this, 'z', z); - RealmObjectBase.set(this, 'a', a); - RealmObjectBase.set(this, 'b', b); - RealmObjectBase.set>(this, 's', RealmList(s)); - RealmObjectBase.set>(this, 't', RealmMap(t)); - RealmObjectBase.set>(this, 'u', RealmSet(u)); - RealmObjectBase.set>(this, 'v', RealmList(v)); - RealmObjectBase.set>(this, 'w', RealmMap(w)); + RealmObjectBase.set(this, 'zero', zero); + RealmObjectBase.set(this, 'minusOne', minusOne); + RealmObjectBase.set(this, 'fooOrOne', fooOrOne); + RealmObjectBase.set(this, 'parenthesis', parenthesis); + RealmObjectBase.set(this, 'minusMinusOne', minusMinusOne); + RealmObjectBase.set(this, 'add', add); + RealmObjectBase.set(this, 'fooEnv', fooEnv); + RealmObjectBase.set(this, 'fooLit', fooLit); + RealmObjectBase.set>( + this, 'constEmptyList', RealmList(constEmptyList)); + RealmObjectBase.set>( + this, 'constEmptyMap', RealmMap(constEmptyMap)); + RealmObjectBase.set>( + this, 'constEmptySet', RealmSet(constEmptySet)); + RealmObjectBase.set>( + this, 'emptyList', RealmList(emptyList)); + RealmObjectBase.set>( + this, 'emptyMao', RealmMap(emptyMao)); + RealmObjectBase.set>( + this, 'emptySet', RealmSet(emptySet)); } - ConstInitizers._(); + ConstInitializer._(); @override - int get x => RealmObjectBase.get(this, 'x') as int; + int get zero => RealmObjectBase.get(this, 'zero') as int; @override - set x(int value) => RealmObjectBase.set(this, 'x', value); + set zero(int value) => RealmObjectBase.set(this, 'zero', value); @override - int get y => RealmObjectBase.get(this, 'y') as int; + int get minusOne => RealmObjectBase.get(this, 'minusOne') as int; @override - set y(int value) => RealmObjectBase.set(this, 'y', value); + set minusOne(int value) => RealmObjectBase.set(this, 'minusOne', value); @override - int get z => RealmObjectBase.get(this, 'z') as int; + int get fooOrOne => RealmObjectBase.get(this, 'fooOrOne') as int; @override - set z(int value) => RealmObjectBase.set(this, 'z', value); + set fooOrOne(int value) => RealmObjectBase.set(this, 'fooOrOne', value); @override - String get a => RealmObjectBase.get(this, 'a') as String; + int get parenthesis => RealmObjectBase.get(this, 'parenthesis') as int; @override - set a(String value) => RealmObjectBase.set(this, 'a', value); + set parenthesis(int value) => RealmObjectBase.set(this, 'parenthesis', value); @override - String get b => RealmObjectBase.get(this, 'b') as String; + int get minusMinusOne => + RealmObjectBase.get(this, 'minusMinusOne') as int; @override - set b(String value) => RealmObjectBase.set(this, 'b', value); + set minusMinusOne(int value) => + RealmObjectBase.set(this, 'minusMinusOne', value); @override - RealmList get s => RealmObjectBase.get(this, 's') as RealmList; + int get add => RealmObjectBase.get(this, 'add') as int; @override - set s(covariant RealmList value) => throw RealmUnsupportedSetError(); + set add(int value) => RealmObjectBase.set(this, 'add', value); @override - RealmMap get t => RealmObjectBase.get(this, 't') as RealmMap; + String get fooEnv => RealmObjectBase.get(this, 'fooEnv') as String; @override - set t(covariant RealmMap value) => throw RealmUnsupportedSetError(); + set fooEnv(String value) => RealmObjectBase.set(this, 'fooEnv', value); @override - RealmSet get u => RealmObjectBase.get(this, 'u') as RealmSet; + String get fooLit => RealmObjectBase.get(this, 'fooLit') as String; @override - set u(covariant RealmSet value) => throw RealmUnsupportedSetError(); + set fooLit(String value) => RealmObjectBase.set(this, 'fooLit', value); @override - RealmList get v => RealmObjectBase.get(this, 'v') as RealmList; + RealmList get constEmptyList => + RealmObjectBase.get(this, 'constEmptyList') as RealmList; @override - set v(covariant RealmList value) => throw RealmUnsupportedSetError(); + set constEmptyList(covariant RealmList value) => + throw RealmUnsupportedSetError(); @override - RealmMap get w => RealmObjectBase.get(this, 'w') as RealmMap; + RealmMap get constEmptyMap => + RealmObjectBase.get(this, 'constEmptyMap') as RealmMap; @override - set w(covariant RealmMap value) => throw RealmUnsupportedSetError(); + set constEmptyMap(covariant RealmMap value) => + throw RealmUnsupportedSetError(); @override - Stream> get changes => - RealmObjectBase.getChanges(this); + RealmSet get constEmptySet => + RealmObjectBase.get(this, 'constEmptySet') as RealmSet; + @override + set constEmptySet(covariant RealmSet value) => + throw RealmUnsupportedSetError(); @override - ConstInitizers freeze() => RealmObjectBase.freezeObject(this); + RealmList get emptyList => + RealmObjectBase.get(this, 'emptyList') as RealmList; + @override + set emptyList(covariant RealmList value) => + throw RealmUnsupportedSetError(); + + @override + RealmMap get emptyMao => + RealmObjectBase.get(this, 'emptyMao') as RealmMap; + @override + set emptyMao(covariant RealmMap value) => + throw RealmUnsupportedSetError(); + + @override + RealmSet get emptySet => + RealmObjectBase.get(this, 'emptySet') as RealmSet; + @override + set emptySet(covariant RealmSet value) => + throw RealmUnsupportedSetError(); + + @override + Stream> get changes => + RealmObjectBase.getChanges(this); + + @override + ConstInitializer freeze() => + RealmObjectBase.freezeObject(this); EJsonValue toEJson() { return { - 'x': x.toEJson(), - 'y': y.toEJson(), - 'z': z.toEJson(), - 'a': a.toEJson(), - 'b': b.toEJson(), - 's': s.toEJson(), - 't': t.toEJson(), - 'u': u.toEJson(), - 'v': v.toEJson(), - 'w': w.toEJson(), + 'zero': zero.toEJson(), + 'minusOne': minusOne.toEJson(), + 'fooOrOne': fooOrOne.toEJson(), + 'parenthesis': parenthesis.toEJson(), + 'minusMinusOne': minusMinusOne.toEJson(), + 'add': add.toEJson(), + 'fooEnv': fooEnv.toEJson(), + 'fooLit': fooLit.toEJson(), + 'constEmptyList': constEmptyList.toEJson(), + 'constEmptyMap': constEmptyMap.toEJson(), + 'constEmptySet': constEmptySet.toEJson(), + 'emptyList': emptyList.toEJson(), + 'emptyMao': emptyMao.toEJson(), + 'emptySet': emptySet.toEJson(), }; } - static EJsonValue _toEJson(ConstInitizers value) => value.toEJson(); - static ConstInitizers _fromEJson(EJsonValue ejson) { + static EJsonValue _toEJson(ConstInitializer value) => value.toEJson(); + static ConstInitializer _fromEJson(EJsonValue ejson) { return switch (ejson) { { - 'x': EJsonValue x, - 'y': EJsonValue y, - 'z': EJsonValue z, - 'a': EJsonValue a, - 'b': EJsonValue b, - 's': EJsonValue s, - 't': EJsonValue t, - 'u': EJsonValue u, - 'v': EJsonValue v, - 'w': EJsonValue w, + 'zero': EJsonValue zero, + 'minusOne': EJsonValue minusOne, + 'fooOrOne': EJsonValue fooOrOne, + 'parenthesis': EJsonValue parenthesis, + 'minusMinusOne': EJsonValue minusMinusOne, + 'add': EJsonValue add, + 'fooEnv': EJsonValue fooEnv, + 'fooLit': EJsonValue fooLit, + 'constEmptyList': EJsonValue constEmptyList, + 'constEmptyMap': EJsonValue constEmptyMap, + 'constEmptySet': EJsonValue constEmptySet, + 'emptyList': EJsonValue emptyList, + 'emptyMao': EJsonValue emptyMao, + 'emptySet': EJsonValue emptySet, } => - ConstInitizers( - x: fromEJson(x), - y: fromEJson(y), - z: fromEJson(z), - a: fromEJson(a), - b: fromEJson(b), - s: fromEJson(s), - t: fromEJson(t), - u: fromEJson(u), - v: fromEJson(v), - w: fromEJson(w), + ConstInitializer( + zero: fromEJson(zero), + minusOne: fromEJson(minusOne), + fooOrOne: fromEJson(fooOrOne), + parenthesis: fromEJson(parenthesis), + minusMinusOne: fromEJson(minusMinusOne), + add: fromEJson(add), + fooEnv: fromEJson(fooEnv), + fooLit: fromEJson(fooLit), + constEmptyList: fromEJson(constEmptyList), + constEmptyMap: fromEJson(constEmptyMap), + constEmptySet: fromEJson(constEmptySet), + emptyList: fromEJson(emptyList), + emptyMao: fromEJson(emptyMao), + emptySet: fromEJson(emptySet), ), _ => raiseInvalidEJson(ejson), }; } static final schema = () { - RealmObjectBase.registerFactory(ConstInitizers._); + RealmObjectBase.registerFactory(ConstInitializer._); register(_toEJson, _fromEJson); return SchemaObject( - ObjectType.realmObject, ConstInitizers, 'ConstInitizers', [ - SchemaProperty('x', RealmPropertyType.int), - SchemaProperty('y', RealmPropertyType.int), - SchemaProperty('z', RealmPropertyType.int), - SchemaProperty('a', RealmPropertyType.string), - SchemaProperty('b', RealmPropertyType.string), - SchemaProperty('s', RealmPropertyType.int, + ObjectType.realmObject, ConstInitializer, 'ConstInitializer', [ + SchemaProperty('zero', RealmPropertyType.int), + SchemaProperty('minusOne', RealmPropertyType.int), + SchemaProperty('fooOrOne', RealmPropertyType.int), + SchemaProperty('parenthesis', RealmPropertyType.int), + SchemaProperty('minusMinusOne', RealmPropertyType.int), + SchemaProperty('add', RealmPropertyType.int), + SchemaProperty('fooEnv', RealmPropertyType.string), + SchemaProperty('fooLit', RealmPropertyType.string), + SchemaProperty('constEmptyList', RealmPropertyType.int, collectionType: RealmCollectionType.list), - SchemaProperty('t', RealmPropertyType.int, + SchemaProperty('constEmptyMap', RealmPropertyType.int, collectionType: RealmCollectionType.map), - SchemaProperty('u', RealmPropertyType.int, + SchemaProperty('constEmptySet', RealmPropertyType.int, collectionType: RealmCollectionType.set), - SchemaProperty('v', RealmPropertyType.int, + SchemaProperty('emptyList', RealmPropertyType.int, collectionType: RealmCollectionType.list), - SchemaProperty('w', RealmPropertyType.int, + SchemaProperty('emptyMao', RealmPropertyType.int, collectionType: RealmCollectionType.map), + SchemaProperty('emptySet', RealmPropertyType.int, + collectionType: RealmCollectionType.set), ]); }(); From 75be480dcd30227a35aed0be04a963739c934fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 28 Mar 2024 18:18:42 +0100 Subject: [PATCH 5/5] Add missing file --- .../test/good_test_data/const_initializer.realm.dart | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/realm_generator/test/good_test_data/const_initializer.realm.dart diff --git a/packages/realm_generator/test/good_test_data/const_initializer.realm.dart b/packages/realm_generator/test/good_test_data/const_initializer.realm.dart new file mode 100644 index 000000000..f52e5e45a --- /dev/null +++ b/packages/realm_generator/test/good_test_data/const_initializer.realm.dart @@ -0,0 +1,4 @@ +// MOCK FILE! This file exists to ensure the parent file is valid Dart. +// The parent will be used as input to the realm_generator in a test, and the +// output compared to the .expected file. +part of 'const_initializer.dart';