chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.78k stars 418 forks source link

Improve the error message when resolving call through forwarding #16055

Open rapiz1 opened 4 years ago

rapiz1 commented 4 years ago

Summary of Problem

Given two procedures that have the same name, the compiler should alert an ambiguous call. But compiling the following code that comes with a forwarding produces an irrelevant error message.

Steps to Reproduce

Source Code:

record inner {
    var a = 1;
        proc const size {
            return a;
        }
        proc const size {
            return a;
        }
}
record outer {
    forwarding var instance: inner;
}

var x = new outer();
var a = x.size;
writeln(a);

Errors:

size.chpl:15: error: unresolved call 'outer.size'
size.chpl:3: note: this candidate did not match: inner.const size
size.chpl:15: note: because method call receiver with type outer
size.chpl:1: note: is passed to formal 'const this: inner'
size.chpl:6: note: candidates are: inner.const size
$CHPL_HOME/modules/internal/String.chpl:1135: note:                 const string.sizereturn
note: and 32 other candidates, use --print-all-candidates to see them

Associated Future Test(s):

None

Configuration Information

chpl version 1.23.0 pre-release (a20083d603)
Copyright 2020 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)

CHPL_TARGET_PLATFORM: linux64
CHPL_TARGET_COMPILER: gnu
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: gmp
CHPL_HWLOC: hwloc
CHPL_REGEXP: re2
CHPL_LLVM: none
CHPL_AUX_FILESYS: none

gcc (GCC) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bradcray commented 4 years ago

Given two procedures that have the same name, the compiler should alert an ambiguous call.

Having two procedures with the same name is generally OK since Chapel supports overloading. In this case, the issue is more that the two procedures have the identical signature, right? (e.g., the following works as expected:

record inner {
    var a = 1;
        proc const size(x: int) {
            return a;
        }
        proc const size(x: real) {
            return a;
        }
}
record outer {
    forwarding var instance: inner;
}

var x = new outer();
var a = x.size(1);
var b = x.size(1.2);
writeln(a);
writeln(b);

)

jabraham17 commented 2 months ago

Noting that this issue feels like its in the same vein as https://github.com/chapel-lang/chapel/issues/13027, although this issue is specific to forwarding. Changing new outer to new inner gives the same ambiguous error as https://github.com/chapel-lang/chapel/issues/13027. However, this issue still feels distinct enough to leave open