Skip to content

Float literal in a const is rejected: "expression kind 21 is not comptime-evaluable yet" #1668

Closed

Description

@ehartford

Summary

A top-level const with a float literal initializer fails to compile. Integer consts work. This forces float constants to be declared as integers and cast at every use site.

Reproduction

float_const.w:

const HALF: f64 = 0.5
const WIDTH: i32 = 1280

fn main:
    print(f"{WIDTH as f64 * HALF}")
with run float_const.w

Output:

error: expression kind 21 is not comptime-evaluable yet
 --> float_const.w:1:19
1 | const HALF: f64 = 0.5
  |                   ^^^
error: run failed

Expected

const HALF: f64 = 0.5 compiles, and the program prints 640.

Environment

  • with v0.15.2.1
  • compiler tree at 334739d
  • macOS (Darwin 25.6.0), Apple Silicon

Context

Hit while factoring the arena rectangle in a raylib game (https://github.com/withlang-dev/wipe) into named constants. The workaround in use is pub const ARENA_LEFT: i32 = 24 plus ARENA_LEFT as f64 at each use, which is what the project already did for WIDTH and HEIGHT. The diagnostic also leaks an internal expression-kind number rather than naming the construct.

Activity

  1. added
    bug
    on Sep 25, 2026
  2. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by #1702 (55739d4); battery green, pinned by the behavior tests named in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreproduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions