Fix bug with conflicting names in enum name and variant
Fixes #406
Checklist
- [x] An issue to be fixed by this PR is listed above.
- [x] New tests are added to ensure new features are working. End-to-end tests are usually in the
./frb_example/pure_dartexample, more specifically,rust/src/api.rsanddart/lib/main.dart. - [x] The code generator has been run, and code changes are commited. (Otherwise, CI will fail.)
- [ ] If this PR adds/changes features, documentations (in the
./bookfolder) are updated. - [x] CI is passing.
Ok so far I got the generator generates files that compile, but somehow I broke the tests :boom: :boom: :boom: 😅 I definitely could use some help here ! ^^
Also, as you will see from regenerated files, the naming might not be to your liking. What I came up here is to rename the enum's variants generated classes for example.
So now they are generated in the form enum_name_variant_name_Variant.
For example this:
#[derive(Debug, Clone)]
#[frb(freezed)]
pub enum Speed {
Unknown,
GPS(f64),
}
Will generate e.g. a class like Speed_Unknown_Variant and Speed_GPS_Variant.
:warning: Please note that I only modified the generated classes / variables / etc only where necessary, leaving all the rest of the code untouched.
:microscope: I initially generated git patches files to investigate (and the error with conflicting names becomes quite apparent) but I can't join them with *.patch extension, so I'm gonna rename them as *.txt.
conflicting_sample.enum_variant_matches_another_enum_name.txt conflicting_sample.enum_variant_matches_another_enum_variant.txt working_sample.txt
Will generate e.g. a class like Speed_Unknown_Variant and Speed_GPS_Variant.
Another proposal: Shall we call it SpeedUnknown, SpeedGPS etc, unconditionally (i.e. always name like that)? I feel it a bit more like Speed::Unknown. And moreover, in freezed, it is not uncommon to see namings like this.
Since the great enhanced enum feature is impl by desdaemon, /cc @Desdaemon what do you think?
but somehow I broke the tests
CI looks good so far :)
Anyway I will wait until this PR is marked as ready for review and then review it.
CI looks good so far :)
hey yeah, I was suprised because on my machine just test-pure fails (to load dynamic library) :)
click to see error details
cd frb_example/pure_dart/dart && dart pub get && dart lib/main.dart ../rust/target/debug/libflutter_rust_bridge_example.dylib
Resolving dependencies... (1.2s)
Got dependencies!
flutter_rust_bridge example program start (dylibPath=../rust/target/debug/libflutter_rust_bridge_example.dylib)
construct api
Unhandled exception:
Invalid argument(s): Failed to load dynamic library '../rust/target/debug/libflutter_rust_bridge_example.dylib': dlopen(../rust/target/debug/libflutter_rust_bridge_example.dylib, 0x0001): tried: '/opt/homebrew/Cellar/dart/2.17.6/libexec/bin/./../rust/target/debug/libflutter_rust_bridge_example.dylib' (no such file), '/opt/homebrew/Cellar/dart/2.17.6/libexec/bin/../../../../rust/target/debug/libflutter_rust_bridge_example.dylib' (no such file), '/opt/homebrew/Cellar/dart/2.17.6/libexec/bin/Frameworks/../rust/target/debug/libflutter_rust_bridge_example.dylib' (no such file), '/opt/homebrew/Cellar/dart/2.17.6/libexec/bin/./../rust/target/debug/libflutter_rust_bridge_example.dylib' (no such file), '/opt/homebrew/Cellar/dart/2.17.6/libexec/bin/../../../../rust/target/debug/libflutter_rust_bridge_example.dylib' (no such file), '/opt/homebrew/Cellar/dart/2.17.6/libexec/bin/Frameworks/../rust/target/debug/libflutter_rust_bridge_example.dylib' (no such file), '../rust/target/debug/libflutter_rust_bridge_example.dylib' (relative path not allowed in hardened program)
#0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:12:43)
#1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:23:12)
#2 main (package:flutter_rust_bridge_example/main.dart:12:32)
#3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
error: Recipe `test-pure` failed on line 46 with exit code 255
What is weird regarding the failure at running just test-pure locally is that it cannot find the compiled libflutter_rust_bridge_example.dylib inside ../rust/target/debug/ but I re-ran cargo build already, checked its presence and still get the same error.
"relative path not allowed in hardened program"
is that some cause?
Anyway, as long as CI is happy we are surely happy :)
ok @fzyzcjy waiting for your review :)
Great job! Since it looks nontrivial, I will review it tomorrow morning (~8hr from now) :)
Oops misclicked that button. Meant to click that for another PR