dart-lang / language

Design of the Dart language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tick marks for macros

nate-thegrate opened this issue · comments

Markdown uses `tick marks` for code snippets: when I type 1 + 2 = 3 it isn't executed anywhere; instead it's visually formatted as code.

Swift, JavaScript, and the Linux shell each have a unique way of interpreting tick marks, but all 3 have the same intuition: `it's a midway point between a string and a code segment.`

This concept relates to one of the main problems presented in a recent Flutter Design Doc:

assert(startValue >= 0)     // easy to debug

@Assert("startValue >= 0")  // more difficult to debug

Proposal

@Assert(`startValue >= 0`)  // technically a String, but supports syntax highlighting,
                            // and is targeted by static analysis

For macro constructor calls we currently have specificied some implicit conversions to Code objects, so you could just do @Assert(startValue => 0) as an example, and the macro would actually get a Code object representing that expression.

But, I think we are going to remove these implicit conversions, as they are too specialized to macros and don't generalize to regular metadata annotations (which I think Assert is in this example).

We do still want some way of passing a Code expression to a macro though, so we probably do want some way of creating a "meta expression" type thing, which is given as Code to the macro, and is statically analyzed. This might be a reasonable syntax for that.