Files
swift-mirror/test/ConstValues/IntegerExpressionsSyntactic.swift
Artem Chikin 0bbd35242c [Literal Expressions] Add support for simple constant-folded literal expressions
This change adds an experimental feature 'LiteralExpressions` which allows for use of simple binary expressions of integer type composed of literal value operands.

For now, such literal expressions are only supported in initializers of '@section` values.
2026-02-09 11:35:45 +00:00

12 lines
552 B
Swift

// Constant globals on integer expressions
// REQUIRES: swift_feature_CompileTimeValues
// REQUIRES: optimized_stdlib
// RUN: %target-swift-frontend -emit-ir -primary-file %s -parse-as-library -enable-experimental-feature CompileTimeValues -verify
@const let constGlobal1: Int = (42 + 42 + 42) / 3
@const let constGlobal2: Int = MemoryLayout<UInt32>.size + 4
// expected-error@-1{{in a literal expression}}
@const let constGlobal3: Int = Int(17.0 / 3.5)
@const let constGlobal4: Int = constGlobal1 + 1
@const let constGlobal5: Int = -constGlobal1 + 1