The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

sanjay_si (7) [Avatar] Offline
It says that
when false: 
is checked by compiler for syntactically correct

The compiler will still parse the code and ensure that the code is still syntactically valid, but the code will not be included in the resulting program. This is because the compiler checks when statements at compile-time.

However the following lines of code does not throw any error even if it is not correct:

when false:
  "blah blah blah blah..."
  var i = 0
  i = "string value - must throw an error"

Am I missing something?
dom96 (75) [Avatar] Offline
Nice catch! It seems this is a bug:
dom96 (75) [Avatar] Offline
Although, I just noticed. Your example, syntactically speaking, is perfectly valid.
sanjay_si (7) [Avatar] Offline
dom96 wrote:Although, I just noticed. Your example, syntactically speaking, is perfectly valid.

Hi Dom, first of all I want to thank you for writing such an excellent book on Nim. It ignited my passion to learn Nim and also became sponsor on bountysource. The book is ideal for experience programmer and they would be enjoying since it does not cover toy examples.

Coming to the point, syntactically the code is not correct. The statement
var i = 0 
implies i is an int. And then in next line it is assigned to string for which the compiler throws an error. Also the first line
"blah blah..." 
throws compiler error.
dom96 (75) [Avatar] Offline
I'm happy to hear that you're enjoying the book!

Syntactically that code is correct, there is no syntax error in it. The error is a "semantic error" because the types are not compatible and the compiler doesn't check the body of a when false statement for semantic errors.