Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class containing two lists with owned elements fails to compile #22261

Open
jabraham17 opened this issue May 8, 2023 · 1 comment
Open

Class containing two lists with owned elements fails to compile #22261

jabraham17 opened this issue May 8, 2023 · 1 comment

Comments

@jabraham17
Copy link
Member

Summary of Problem

Trying to write a class which holds two lists with two different element types fails. In the below example, if both lists contain owned A, it compiles. This is also independent of which class is used. The below example declares list a then b, and results in an error complaining about b. Switching these to declare b then a results in the same error, instead complaining about a. Changing the second definition to store nilable classes does allow it to compile.

Steps to Reproduce

Source Code:

use List;
class A {}
class B {}

class C {
var a = new list(owned A);
var b = new list(owned B);
}
proc main() {
var c = new C();
}

Compile command:
chpl test.chpl

$CHPL_HOME/modules/standard/List.chpl:402: In method '_commonInitFromIterable':
$CHPL_HOME/modules/standard/List.chpl:405: error: Cannot transfer ownership from this non-nilable reference variable
  $CHPL_HOME/modules/standard/List.chpl:313: called as (list(owned B,false))._commonInitFromIterable(iterable: list(owned B,false)) from method 'init='
  $CHPL_HOME/modules/internal/ChapelBase.chpl:1826: called as (list(owned B,false)).init=(other: list(owned B,false))
note: generic instantiations are underlined in the above callstack

Configuration Information

  • Output of chpl --version:
chpl version 1.31.0 pre-release (4112d47eae)
  built with LLVM version 14.0.6
  available LLVM targets: amdgcn, r600, nvptx64, nvptx, aarch64_32, aarch64_be, aarch64, arm64_32, arm64, x86-64, x86
Copyright 2020-2023 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: llvm
CHPL_TARGET_ARCH: arm64
CHPL_TARGET_CPU: native *
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: fifo
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: cstdlib
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled
CHPL_HWLOC: none
CHPL_RE2: bundled
CHPL_LLVM: bundled *
CHPL_AUX_FILESYS: none
  • Back-end compiler and version, e.g. gcc --version or clang --version:
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
@cassella
Copy link
Contributor

cassella commented May 9, 2023

I get the same error when the two lists are defined at the top-level:

use List;
class A {}
class B {}

var a = new list(owned A);
var b = new list(owned B);

Changing the second definition to store nilable classes does allow it to compile.

Making the first list store nilable A also clears the errors about B:

use List;
class A {}
class B {}

var a = new list(owned A?);
var b = new list(owned B);

There's no error from making B a type alias of A:

use List;
class A {}
type B = A;

var a = new list(owned A);
var b = new list(owned B);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants