Nim: Compiler can't distinguish proc from field when both identifiers have the same name

Created on 30 Sep 2020  路  2Comments  路  Source: nim-lang/Nim

The compiler can't distinguish proc from field when both identifiers have the same name. I tried compiling the provided example with a func and method instead of proc. Still fails.

To reproduce

type Status = object
    response: string

proc response(s: var Status, r: string) =
    s.response = r

var s: Status
s.response("stoof")

Current Output

~ $ nim cc .\main.nim
Hint: used config file 'C:\Program Files\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]      
Hint: main [Processing]
Error: in expression 's.response("stoof")': identifier expected, but found 's.response'

Expected Output

~ $ nim cc .\main.nim
Hint: used config file 'C:\Program Files\Nim\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: main [Processing]
CC: stdlib_system.nim
CC: main.nim
Hint:  [Link]
Hint: 14208 LOC; 0.833 sec; 16.133MiB peakmem; Debug build; proj: ~\Downloads\main.nim; out: ~\Downloads\main.exe [SuccessX]

Additional Information

~ $ nim -v
Nim Compiler Version 1.2.6 [Windows: amd64]
Compiled at 2020-07-29
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: bf320ed172f74f60fd274338e82bdc9ce3520dd9
active boot switches: -d:release
Feature

Most helpful comment

Field accesses take priority over scope expansions. Not sure if there is a bug here.

All 2 comments

Field accesses take priority over scope expansions. Not sure if there is a bug here.

If not considered as a bug, would you consider it as a feature then?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vindaar picture Vindaar  路  3Comments

juancarlospaco picture juancarlospaco  路  3Comments

timotheecour picture timotheecour  路  3Comments

teroz picture teroz  路  3Comments

koki-koba picture koki-koba  路  3Comments