<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 13, 2017, at 4:00 PM, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 11, 2017, at 2:59 PM, Mohammed Ennabah via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><ul class="MailOutline"><li class="">I dug into the codebase as stated in the steps you mentioned, and tried to change one of the errors to see if it really change when I use Swift REPL, but nothing changed. Is it possible that I change something and directly affect the Swift compiler? (maybe I need to do a build first? Or maybe related to xcode-select?)</li></ul></div></div></blockquote><div class=""><br class=""></div><div class="">If you just type "swift" at the command line, you'll run the version of Swift built into Xcode. You will need to build Swift first ("utils/build-script" is the easiest way, but not the fastest), and you will also need to run the version of the Swift interpreter you just built. You can do that with a command like:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift</div><div class=""><br class=""></div><div class="">(The path will be a little different if you use the "-x" flag to build-script, which generates an Xcode project, albeit one that's a pain to use.)</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><ul class="MailOutline"><li class="">Each type of&nbsp;diagnostics has 4 parts,&nbsp;ERROR(ID,Options,Text,Signature). Diagnostics use the first 3 parts and pass&nbsp;parentheses&nbsp;to the&nbsp;signature. What is meant by the&nbsp;signature&nbsp;and why it’s used?</li></ul></div></div></blockquote><br class=""></div><div class="">Error messages actually use a sort of format string language similar to printf(); for those messages which take parameters, the signature gives their types. For example, DiagnosticsParse.def includes this error:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>ERROR(expected_identifier_in_decl,none,</div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;&nbsp;"expected identifier in %0 declaration", (StringRef))<br class=""><br class=""><div class="">So code which emits that error must include a string to put in place of the "%0" token:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// When we write "import" followed by a keyword that isn't "class", "struct", "protocol", etc.:</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>diagnose(Tok,&nbsp;diag::expected_identifier_in_decl,&nbsp;"import");<br class=""></div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// When we try to parse an identifier after e.g. "typealias" and don't find one:</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>P.diagnose(P.Tok,&nbsp;diag::expected_identifier_in_decl, DeclKindName);</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// When we try to parse an identifier after "case" and find some punctuation or a literal:<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>diagnose(CaseLoc,&nbsp;diag::expected_identifier_in_decl,&nbsp;"enum 'case'");</div><div class=""><br class=""></div><div class="">Strings are the most common kind of parameter, but you can also pass other types and choose between different wordings based on them. For instance, here's a fix-it note I added for multiline string literals which takes a boolean to indicate singular or plural:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>NOTE(lex_multiline_string_indent_change_line,none,<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;&nbsp;"change indentation of %select{this line|these lines}0 to match closing delimiter", (bool))<br class=""><br class=""></div><div class="">This error, which is shown when there's a non-digit in an integer literal, takes both a string containing the bad character, and a number (0 to 3) indicating which literal format it was parsing:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>ERROR(lex_invalid_digit_in_int_literal,none,<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;&nbsp;"'%0' is not a valid %select{binary digit (0 or 1)|octal digit (0-7)|"<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;&nbsp;"digit|hexadecimal digit (0-9, A-F)}1 in integer literal",<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;&nbsp;(StringRef, unsigned))<br class=""></div><div class=""><br class=""></div><div class="">If you look around that file and the other Diagnostics*.def files, you'll see some other interesting examples. Have fun poking around!</div><br class=""></div></div></blockquote><div><br class=""></div><div>Good work. I believe that these are pretty good examples to understand how the Swift diagnosis work in practice.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">--&nbsp;</div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>

</div>
<br class=""></div></div></blockquote></div><br class=""></body></html>