Macros Introduction

I'm using

$ swift -v
Swift version 5.9-dev (LLVM 84aca0981812b32, Swift 8790101221df99d)
Target: x86_64-unknown-linux-gnu

and I wanted to experiment with the new feature Macros but i keep getting this errors

error: macros are an experimental feature that is not enabled
@freestanding(expression) public macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "Macros", type: "StringifyMacro")

and this one too

warning: external macro implementation type 'Macros.StringifyMacro' could not be found for macro 'stringify'; the type must be public and provided via '-load-plugin-library'

and even tried the enable-experimental-feature flag and still nothing

$ swift build  -Xswiftc='-enable-experimental-feature macros'
Building for debugging...
error: unknown argument: '-enable-experimental-feature macros'
error: unknown argument: '-enable-experimental-feature macros'

Can anyone help me out?

File organization:

2 Likes

I missed this message before, sorry.

Experimental feature names are case-sensitive, so this would need to be spelled --enable-experimental-feature Macros. However, if you grab a newer snapshot from swift.org you won't need the flag at all.

The easiest way to get started is generally to use the macro examples project.

Doug

I've downloaded the latest development swift version but a new error pops up

error: macros are not supported in this compiler
2 Likes