Skip to content

Switch expression on "this" causes "Syntax node is not within syntax tree" ArgumentExpression in ProjectionExpressionGenerator #213

Description

@Xriuk

I am working around the limitations of #74 and I have code like this, which is working:

[Projectable(UseMemberBody = nameof(MyFuncInternal), AllowBlockBody = true)]
public virtual string? MyFunc() {
	return ...;
}
internal string? MyFuncInternal(){
	if(this is DerivedType1)
		return ((DerivedType1)this).MyFunc();
	else if(this is DerivedType2)
		return ((DerivedType2)this).MyFunc();
	else
		return null;
}

However since Type casting is not supported inside ifs (if(this is DerivedType1 t1) t1...) I have to resort to switch expressions, however this doesn't seem to work I'm just getting a silent message ArgumentExpression "Syntax node is not within syntax tree" in ProjectionExpressionGenerator and not much else, and no source files are generated.

[Projectable(UseMemberBody = nameof(MyFuncInternal))]
public virtual string? MyFunc() {
	return ...;
}
internal string? MyFuncInternal() => this switch {
	DerivedType1 t1 => t1.MyFunc(),
	DerivedType2 t2 => t2.MyFunc(),
	_ => null
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions