Skip to content

[Bug] Compiler fails with wrong return type for operator #2425

@zerkawei

Description

@zerkawei

The following code fails to build on Linux (couldn't reproduce on Windows) :

public struct FooBar
{
	public const Self Const = .(); // Has to be const

	public static Bar operator+(Self a, Object b) // Has to be an operator that returns Bar
	{
		return default; // Return value not relevant
	}

}

public struct Foo
{
	protected float[1] e; // Has to be fixed size array (size not relevant) of float or double
}

public struct Bar : Foo // Has to be derived
{
}

public class Program
{
	public static void Main()
	{
		Bar required = .(); // Has to be a new Bar instance

		let error = (FooBar.Const + null); // Has to involve at least one const FooBar (other value not relevant)
	} 
}

With the following error :

Function return type does not match operand type of return inst!
  ret float %2, !dbg !37
 i32

Inspecting the IR shows that the operator is incorrectly marked has returning i32 rather than float here

define i32 @_ZN2bf8TestZone6FooBarplES1_PNS_6System6ObjectE(ptr %b) #0 !dbg !4 {

Tested on latest nightly (03/27/2026)

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