rumble icon indicating copy to clipboard operation
rumble copied to clipboard

declare variable as double does not perform automatic promotion

Open mario-arduini opened this issue 5 years ago • 2 comments

declaring variable as double do not perform automatic promotion from decimal or integer input but throws an error

e.g. declare variable $a as double := 3; $a Throws XPTY0004: integer is not expected here. The expected type is double

note that automatic promotion works for example from integer to decimal

mario-arduini avatar Oct 29 '20 13:10 mario-arduini

Thank you for submitting this.

I am not quite sure that type promotion is performed for variable declarations. Zorba, the reference implementation, outputs the same error.

The spec says that type promotion "is used in evaluating function calls (see 3.1.5.1 Evaluating Static and Dynamic Function Calls ), order by clauses (see 3.10.8 Order By Clause), and operators that accept numeric or string operands (see B.2 Operator Mapping).]"

and the variable declaration section says "In all cases the value V must match the type T according to the rules for SequenceType matching; otherwise a type error is raised [err:XPTY0004]." which also does not include type promotion.

ghislainfourny avatar Nov 09 '20 10:11 ghislainfourny

Thank you for the answer. I agree with your interpretation, but is it possible that in this case we have a bug with decimal declaration? For example:

declare variable $a as decimal := 12; $a

is allowed, even if 12 should be an integerLiteral, so in this case we should not allowed automatic promotion to decimal and throw XPTY0004 error.

mario-arduini avatar Nov 09 '20 11:11 mario-arduini