mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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
This commit is contained in:
20
test/ConstValues/DiagModulesSyntactic.swift
Normal file
20
test/ConstValues/DiagModulesSyntactic.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
// Constant globals should "work" even when used across files in non-WMO builds.
|
||||
// REQUIRES: swift_feature_CompileTimeValues
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: split-file %s %t
|
||||
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -parse-as-library -enable-experimental-feature CompileTimeValues
|
||||
// RUN: %target-swift-frontend -emit-ir -I %t %t/Main.swift -verify -enable-experimental-feature CompileTimeValues
|
||||
|
||||
//--- MyModule.swift
|
||||
|
||||
public func foo() -> Int {
|
||||
return 42
|
||||
}
|
||||
|
||||
//--- Main.swift
|
||||
|
||||
import MyModule
|
||||
|
||||
@const let constGlobal1: Int = foo()
|
||||
// expected-error@-1 {{not supported in a '@const' expression}}
|
||||
Reference in New Issue
Block a user