nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

Compiler can't distinguish proc from field when both identifiers have the same name #15438

Open Soupertonic opened 4 years ago

Soupertonic commented 4 years ago

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
Araq commented 4 years ago

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

Soupertonic commented 4 years ago

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