Skip to content

Constant fold toInt, toLong, toDouble, toFloat, toByte and toShort #13990

Closed
@nicolasstucki

Description

@nicolasstucki

Compiler version

3.1.0

Minimized code

inline val myIntMask = 1 << 4
inline val myLongMask = myIntMask.toLong

Output

2 |inline val myLongMask = myIntMask.toLong
  |                        ^^^^^^^^^^^^^^^^
  |                        inline value must have a literal constant type

Expectation

We should be able to constant fold toInt, toLong, toDouble, toFloat, toByte and toShort.

This would also alow us to write inline vals with Short and Byte types as shown bellow

inline val myByteMask = 2.toByte

This is currently impossible as we do not possess a byte or short numerical postfix in the syntax.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions