[swift-evolution] Proposal: Allow functions to participate in the compile so they can generate warnings about their usage.

Andrew Bennett cacoyi at gmail.com
Sat Feb 13 21:39:21 CST 2016


Fantastic idea, it would be nice to be able to do this in such a way that
it didn't bloat out a function's definition. This is similar to the
code-by-contract discussions that have happened in the past. This may be
breaking into macro territory though. Perhaps it could be expressed like
this:

@callVerification func verifyNoLiterals(inNode node: ASTNode) ->
[CallVerificationError] {
    ...
}

@verifyCall(noLiterals)
func precondition(success: Bool) {
    ...
}


On Sat, Feb 13, 2016 at 8:15 AM, Amir Michail via swift-evolution <
swift-evolution at swift.org> wrote:

> For example, the Swift standard library might want to ensure that you use
> "preconditionFailure()" instead of "precondition(false)" since the former
> doesn’t get in the way of constant/variable initialization static analysis.
>
> So maybe allow functions to have a warning clause with an abstract syntax
> tree parameter allowing the function to examine its usage context in the
> source code and issue warnings correspondingly that appear during the
> compile.
>
> Here’s some related work:
> https://msdn.microsoft.com/en-us/magazine/dn879356.aspx
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160214/266b79a3/attachment.html>


More information about the swift-evolution mailing list