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

[cs] StackOverflowException when using abstract builder with fluent API #10930

Closed
sebthom opened this issue Jan 18, 2023 · 0 comments · Fixed by #11551
Closed

[cs] StackOverflowException when using abstract builder with fluent API #10930

sebthom opened this issue Jan 18, 2023 · 0 comments · Fixed by #11551
Milestone

Comments

@sebthom
Copy link
Contributor

sebthom commented Jan 18, 2023

The following code results in a StackOverflowException when targeting CSharp, but works for all other targets:

abstract class AbstractFluentObject<This:AbstractFluentObject<This>> {
   public function new() {}
   public function setName(name:String):This {
      return cast this;
   }
}

class ConcreteFluentObject extends AbstractFluentObject<ConcreteFluentObject> {
   public function new() {
      super();
   }
}

class Test {
  static function main() {
    trace(new ConcreteFluentObject().setName("test"));
  }
}

If I remove the abstract keyword, then the StackOverflowException goes way.

If the abstract keyword is present the following code is generated which results in the StackOverflow:

public virtual object AbstractFluentObject_cast<This_c>() {
   return this.AbstractFluentObject_cast<This>();
}

If I remove the abstract keyword, this code is generated:

public virtual object AbstractFluentObject_cast<This_c>() {
	if (global::haxe.lang.Runtime.eq(typeof(This), typeof(This_c))) {
		return this;
	}
			
	global::AbstractFluentObject<This_c> new_me = new global::AbstractFluentObject<This_c>(global::haxe.lang.EmptyObject.EMPTY);
	global::Array<string> fields = global::Reflect.fields(this);
	int i = 0;
	while (( i < fields.length )) {
		string field = fields[i++];
		global::Reflect.setField(new_me, field, global::Reflect.field(this, field));
	}
	
	return new_me;
}
@sebthom sebthom changed the title [cs] StackOverflowException when implementing builder with fluent API [cs] StackOverflowException when using abstract builder with fluent API Jan 18, 2023
@Simn Simn added this to the Later milestone Mar 24, 2023
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 a pull request may close this issue.

2 participants