Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support for StringBuilder.Chars for Rust #3760

Closed
wants to merge 1 commit into from

Conversation

MangelMaxime
Copy link
Member

Hello @ncave ,

While trying to add support for StringBuilder.Charts to Rust I run into an issue where fable-library-rust cannot be compiled.

Checking fable_library_rust v0.1.0 (/Users/mmangel/Workspaces/Github/fable-compiler/Fable/temp/fable-library-rust)
error[E0599]: no method named `Clear` found for reference `&module_5bc0559d::System::Text::StringBuilder` in the current scope
   --> src/./System.Text.rs:210:37
    |
210 | ...                   (_self_.Clear()).Append_Z372E4D23(bufferText_1);
    |                               ^^^^^ method not found in `&StringBuilder`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
note: `ICollection_1` defines an item `Clear`, perhaps you need to implement it
   --> src/./Interfaces.rs:245:17
    |
245 |                 pub trait ICollection_1<T: Clone + 'static> {
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0599`.
error: could not compile `fable_library_rust` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `fable_library_rust` (lib test) due to previous error

While looking at the generated source code I discovered that member have self: &Lrc<Self> generated but getter/setter have &self.

Manually changing

pub fn set_Chars_413E0D0A(self, index: i32, value: char) {

to

pub fn set_Chars_413E0D0A(self: &Lrc<Self>, index: i32, value: char) {

seems to make the error go away at least in the IDE.

I found that the line responsible for generating &Lrc<Self> is

let makeTypedParam (com: IRustCompiler) ctx (ident: Fable.Ident) returnType =
if ident.IsThisArgument then
// is this a fluent API?
match ident.Type, shouldBeRefCountWrapped com ctx ident.Type with
| Fable.DeclaredType(entRef, genArgs), Some ptrType when ident.Type = returnType ->
// for fluent APIs, set the type of thisArg to (self: &Lrc<Self>)
let ty = mkImplSelfTy ()
let ty =
match ptrType with
| Lrc -> ty |> makeFluentTy com ctx
| Rc -> ty |> makeRcTy com ctx
| Arc -> ty |> makeArcTy com ctx
| Box -> ty |> makeBoxTy com ctx
|> mkRefTy None
mkTypedSelfParam ty false false
| _ -> mkImplSelfParam false false
elif ctx.IsLambda && ident.Type = Fable.Any then
mkInferredParam ident.Name false false
else
let ty = transformType com ctx ident.Type
mkTypedParam ident.Name ty false false

But it doesn't work in the current situation because the ident.Type and returnType are different. I am not sure what is the path of action to take from here.

@ncave
Copy link
Collaborator

ncave commented Feb 18, 2024

@MangelMaxime Thanks, I'll take a look.

@ncave
Copy link
Collaborator

ncave commented Feb 19, 2024

Superseded by #3761.

@ncave ncave closed this Feb 19, 2024
@MangelMaxime MangelMaxime deleted the feature/rust_stringbuilder_chars branch February 19, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants