What's wrong
Static type inference in StandardLanguageGenerator (Coder/Languages/StandardLanguageGenerator.cs:160-161) types:
- a
BinaryExpression as StaticType(Left) ?? StaticType(Right);
- a conditional as the type of its first branch.
There is no numeric promotion. GoGenerator then uses that type for the closure it emits for a conditional (GoGenerator.cs:1658) and for the := local registry.
Reproduction (go build, HEAD ad68d48)
A function returning double contains return abs(ready ? 1 : 2.5). It generates:
abs(func() int { if ready { return 1 }; return 2.5 }())
go build reports:
cannot use 2.5 (untyped float constant) as int value in return statement (truncated)
cannot use func() int {…}() (value of type int) as float64 value
x := 1 + 0.5 is likewise registered as int, which breaks later typed uses of x.
This came in with e2c5afa ("Go type inference"). It is distinct from #134, which is about the nested-conditional closure shape.
Suggested fix / acceptance criteria
- When combining operand or branch types, apply numeric promotion:
float64 over float32 over int64 over int. For example, a ResultType(a, b) helper.
- For the conditional closure, prefer a known target type (the enclosing return type or parameter type) over the inferred branch type.
- Add Go compile tests for a mixed int/float conditional used as an argument and as a return value, and for
x := 1 + 0.5 followed by a float64 use.
What's wrong
Static type inference in
StandardLanguageGenerator(Coder/Languages/StandardLanguageGenerator.cs:160-161) types:BinaryExpressionasStaticType(Left) ?? StaticType(Right);There is no numeric promotion.
GoGeneratorthen uses that type for the closure it emits for a conditional (GoGenerator.cs:1658) and for the:=local registry.Reproduction (go build, HEAD ad68d48)
A function returning
doublecontainsreturn abs(ready ? 1 : 2.5). It generates:go buildreports:cannot use 2.5 (untyped float constant) as int value in return statement (truncated)cannot use func() int {…}() (value of type int) as float64 valuex := 1 + 0.5is likewise registered asint, which breaks later typed uses ofx.This came in with e2c5afa ("Go type inference"). It is distinct from #134, which is about the nested-conditional closure shape.
Suggested fix / acceptance criteria
float64overfloat32overint64overint. For example, aResultType(a, b)helper.x := 1 + 0.5followed by afloat64use.