Files
swift-mirror/test/Sema/reference_bindings.swift
Daniel Rodríguez Troitiño ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00

70 lines
2.5 KiB
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-feature ReferenceBindings
// REQUIRES: swift_feature_ReferenceBindings
var globalValue = String()
class Klass {
var sStored: String = ""
var sGetter: String { fatalError() }
var sModify: String {
_read {
fatalError()
}
_modify {
fatalError()
}
}
}
struct S : ~Copyable {
var sStored: String = ""
var sGetter: String { fatalError() }
var sModify: String {
_read {
fatalError()
}
_modify {
fatalError()
}
}
}
func foo(_ arg: String, _ consumingArg: consuming String, _ borrowingArg: borrowing String, _ inoutArg: inout String) {
let letValue = 5
var varValue = 5
inout noInitialValue: String // expected-error {{inout bindings must have an initial value}}
inout literalX = 5 // expected-error {{inout bindings must be bound to an lvalue}}
inout consumingArgX = consumingArg
inout borrowingArgX = borrowingArg // expected-error {{inout bindings must be bound to an lvalue}}
inout inoutArgX = inoutArg
inout letValueX = letValue // expected-error {{inout bindings must be bound to an lvalue}}
inout varValueX = varValue
inout globalValueX = globalValue
let k = Klass()
inout storedKlassFieldX = k.sStored
inout getterKlassFieldX = k.sGetter // expected-error {{inout bindings must be bound to an lvalue}}
inout modifyKlassFieldX = k.sModify
let letStruct = S()
inout storedStructLetFieldX = letStruct.sStored // expected-error {{inout bindings must be bound to an lvalue}}
inout getterStructLetFieldX = letStruct.sGetter // expected-error {{inout bindings must be bound to an lvalue}}
inout modifyStructLetFieldX = letStruct.sModify // expected-error {{inout bindings must be bound to an lvalue}}
var varStruct = S()
inout storedStructVarFieldX = varStruct.sStored
inout getterStructVarFieldX = varStruct.sGetter // expected-error {{inout bindings must be bound to an lvalue}}
inout modifyStructVarFieldX = varStruct.sModify
}
// Make sure that we get never used to diagnostics, but not never written to diagnostics.
func neverWrittenMutatedDiagnostics() {
var x = "123"
x = "223"
do {
inout x2 = x // expected-warning {{initialization of variable 'x2' was never used; consider replacing with assignment to '_' or removing it}}
}
do {
inout x2 = x
let _ = x2
}
}