Files
swift-mirror/test/ConstValues/Parameters.swift
Artem Chikin d8176a7e89 [Compile Time Values] Add syntactic verification of valid expressions in '@const' contexts
Syntactically verify that initializer expressions of '@const' variables and argument expressions to '@const' parameters consist strictly of syntactically-verifiable set of basic values and operations
2025-05-20 09:38:36 -07:00

19 lines
648 B
Swift

// Constant globals on simple integer literals
// REQUIRES: swift_feature_CompileTimeValues
// REQUIRES: swift_feature_CompileTimeValuesPreview
// RUN: %target-swift-frontend -emit-sil -primary-file %s -verify -enable-experimental-feature CompileTimeValues -enable-experimental-feature CompileTimeValuesPreview
func bar(@const _ thing: UInt) -> UInt {
return thing
}
func foo() {
let _ = bar(42)
let _ = bar(0xf000f000)
#if _pointerBitWidth(_64)
let _ = bar(0xf000f000_f000f000)
#endif
let _ = bar(UInt.random(in: 0..<10))
// expected-error@-1 {{expected a compile-time value argument for a '@const' parameter}}
}