Files
swift-mirror/test/expr/print/conditions.swift
Hamish Knight 2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00

59 lines
1.2 KiB
Swift

// RUN: %target-swift-frontend -print-ast %s 2>&1 | %FileCheck %s
if (5 + 5) == 10 {
}
// CHECK: if (5 + 5) == 10 {
// CHECK: }
if (5 + 5) == 9 {
} else if (5 + 5) == 10 {
} else {
}
// CHECK: if (5 + 5) == 9 {
// CHECK: } else if (5 + 5) == 10 {
// CHECK: } else {
// CHECK: }
guard (5 + 5) == 10 else {
}
// CHECK: guard (5 + 5) == 10 else {
// CHECK: }
var a = 0
// CHECK: @_hasInitialValue internal var a: Int = 0
// Note: the AST doesn't store whitespace,
// so the output doesn't always match the input.
while a < 10 { a += 1 }
// CHECK: while a < 10 {
// CHECK: a += 1
// CHECK: }
var b = 0
repeat {
b += 1
} while b < 10
// CHECK: @_hasInitialValue internal var b: Int = 0
// CHECK: repeat {
// CHECK: b += 1
// CHECK: } while b < 10
var p = (17 > 7 ? true : false)
// CHECK: @_hasInitialValue internal var p: Bool = (17 > 7 ? true : false)
var x: Int = 3
var y: Bool = x is Int
// CHECK: @_hasInitialValue internal var y: Bool = x is Int
enum SomeError: Error {
case errorType
}
func someThrowingFunc() throws -> SomeError {
throw SomeError.errorType
}
var tryExpr = try? someThrowingFunc()
// CHECK: @_hasInitialValue internal var tryExpr: SomeError? = try? someThrowingFunc()
var tryForceExpr = try! someThrowingFunc()