Field and method symbols don't seem to get exported to the user code in the example below. I would expect the methods and fields to be accessible, despite doing a use bash only;.
Source Code:
proc main() {
use bash only;
var p = bash.ls();
var output = p.stdout; // <--- unresolved call 'subprocess(dynamic,true).stdout'
}
module bash {
use spawn;
proc ls(args='') {
var p = spawn.spawnshell('ls ' + args, stdout=spawn.pipe, stderr=spawn.pipe);
p.wait();
return p;
}
}
Compile command:
> chpl userCode.chpl
userCode.chpl:3: In function 'main':
userCode.chpl:8: error: unresolved call 'subprocess(dynamic,true).stdout'
userCode.chpl:8: note: because no functions named stdout found in scope
chpl --version: chpl version 1.21.0 pre-release (f3e74adea4)@lydia-duncan - this is the issue we briefly chatted about yesterday.
Note that this isn't as general as the title implies (suggested title improvements are welcome @bradcray). This only occurs when the type is defined in a module used by a module that is use-only'd. So if I defined a custom type in bash, the fields and methods on that type would get exported correctly.
I think this relates, at least thematically, to issue #14407?
It hasn't be asked in this issue, but I consider this a bug, from the "I want Chapel imports to work like Python" perspective.
Here's the working python equivalent for reference:
"""User code"""
import bash
p = bash.ls()
output = p.stdout.read().decode('utf-8')
print(output)
"""bash.py"""
from subprocess import *
import shlex
def ls(args=''):
p = Popen(shlex.split('ls ' + args), stdout=PIPE,
stderr=PIPE)
p.wait();
return p
Resolved by #15003
Most helpful comment
I think this relates, at least thematically, to issue #14407?