swiftlang/swift-syntax

"`EffectfulExprSyntax`" protocol covering `TryExprSyntax` and `AwaitExprSyntax`

Closed this issue · 2 comments

Description

It'd be very helpful to have a protocol that covers all effectful expressions (currently TryExprSyntax and AwaitExprSyntax.) swift-testing needs to walk syntax trees and diagnose when either of these expression types appear in certain contexts, and because the types are unrelated there is a fair bit of duplicated logic between them.

Tracked in Apple’s issue tracker as rdar://125011703

I did find the time to actually think about it now and wasn’t able to come up with a concise definition that differentiates TryExprSyntax and AwaitExprSyntax from any other syntax nodes, which is usually a very good indicator that we’re not on the right track.
At first I thought that try and await are keywords/modifiers/whatever you want to call them that don’t actually change semantic meaning but just indicate something to anyone reading the code. But TryExprSyntax also represents try! and try?, which do change how the expression behaves. With those in mind, I don’t think there’s anything fundamental that’s separating eg. try? from eg. optional chaining or force-unwrapping and thus it doesn’t make sense to add a syntax trait for them.