Hello everyone!

I'm not sure if this is a bug, so I'm writing this post to avoid creating an 
unnecessary github issue.

In the following proc the result variable is being assigned to, but then there 
is a last statement that would act as the return value. This causes an error as 
expected: 
    
    
    proc foo(name: string): string =
      result = "Hello " & name
      "this is an error"
    
    echo foo("test")
    
    
    Run

Output:

> Error: expression '"this is an error"' is of type 'string' and has to be 
> discarded

But when you change the assignment to .add, the last statement gets returned 
instead of causing an error: 
    
    
    proc foo(name: string): string =
      result.add("Hello " & name)
      "this should be an error"
    
    echo foo("test")
    
    
    Run

Output:

> this should be an error
    
    
    $ nim --version
    
    Nim Compiler Version 1.0.6 [MacOSX: amd64]
    Compiled at 2020-01-29
    Copyright (c) 2006-2019 by Andreas Rumpf
    
    active boot switches: -d:release -d:useLinenoise
    
    
    Run

Reply via email to