Skip to content

class reference to itself in a tuple fails compilation in C++ #1325

Open
@hughdavenport

Description

@hughdavenport

Got the following source:

class A {
    d: [String:(A)]

    public function foo(mut this) throws {
        .d.set("this", (this,))
    }
}

function main() {
    let d: [String:(A)] = [:]
    mut a = A(d)
    a.foo()
    println("OK")
}

Get the error:

Building: 1/4 (jakt__prelude__prelude.cpp)
Building: 2/4 (test.cpp)
build/test.cpp:29:58: error: no viable conversion from 'Tuple<Jakt::A>' to 'Tuple<AK::NonnullRefPtr<Jakt::A>>'
TRY((((((*this).d)).set(Jakt::DeprecatedString("this"sv),(Tuple{*this})))));
                                                         ^~~~~~~~~~~~~~
/home/hugh/src/osdev/jakt//runtime/AK/Try.h:28:39: note: expanded from macro 'TRY'
            auto _temporary_result = (expression));                                                  \
                                      ^~~~~~~~~~
/home/hugh/src/osdev/jakt//runtime/AK/Diagnostics.h:21:5: note: expanded from macro 'AK_IGNORE_DIAGNOSTIC'
    statement;                                \
    ^~~~~~~~~
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:20:5: note: candidate inherited constructor not viable: no known conversion from 'Tuple<Jakt::A>' to 'AK::NonnullRefPtr<Jakt::A> &&' for 1st argument
    Tuple(T&& value)
    ^
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:118:33: note: constructor from base class 'Tuple<AK::NonnullRefPtr<Jakt::A>>' inherited here
    using Detail::Tuple<Ts...>::Tuple;
                                ^
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:26:5: note: candidate inherited constructor not viable: no known conversion from 'Tuple<Jakt::A>' to 'const AK::NonnullRefPtr<Jakt::A> &' for 1st argument
    Tuple(T const& value)
    ^
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:118:33: note: constructor from base class 'Tuple<AK::NonnullRefPtr<Jakt::A>>' inherited here
    using Detail::Tuple<Ts...>::Tuple;
                                ^
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:121:5: note: candidate constructor not viable: no known conversion from 'Tuple<Jakt::A>' to 'AK::Tuple<AK::NonnullRefPtr<Jakt::A>> &&' for 1st argument
    Tuple(Tuple&& other)
    ^
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:126:5: note: candidate constructor not viable: no known conversion from 'Tuple<Jakt::A>' to 'const AK::Tuple<AK::NonnullRefPtr<Jakt::A>> &' for 1st argument
    Tuple(Tuple const& other)
    ^
/home/hugh/src/osdev/jakt//runtime/Builtins/Dictionary.h:66:39: note: passing argument to parameter 'value' here
    ErrorOr<void> set(K const& key, V value)
                                      ^
Building: 3/4 (jakt__prelude__iteration.cpp)
In file included from build/test.cpp:1:
In file included from build/test.h:2:
In file included from build/__unified_forward.h:2:
In file included from /home/hugh/src/osdev/jakt//runtime/lib.h:44:
/home/hugh/src/osdev/jakt//runtime/AK/Tuple.h:27:11: error: call to implicitly-deleted copy constructor of 'Jakt::A'
        : value(value)
          ^     ~~~~~
build/test.cpp:29:59: note: in instantiation of member function 'AK::Detail::Tuple<Jakt::A>::Tuple' requested here
TRY((((((*this).d)).set(Jakt::DeprecatedString("this"sv),(Tuple{*this})))));
                                                          ^
build/test.h:5:11: note: copy constructor of 'A' is implicitly deleted because base class 'RefCounted<Jakt::A>' has a deleted copy constructor
class A : public RefCounted<A>, public Weakable<A> {
          ^
/home/hugh/src/osdev/jakt//runtime/AK/RefCounted.h:55:20: note: copy constructor of 'RefCounted<Jakt::A>' is implicitly deleted because base class 'AK::RefCountedBase' has a deleted copy constructor
class RefCounted : public RefCountedBase {
                   ^
/home/hugh/src/osdev/jakt//runtime/AK/RefCounted.h:17:25: note: 'RefCountedBase' has been explicitly marked deleted here
    AK_MAKE_NONCOPYABLE(RefCountedBase);
                        ^
2 errors generated.
Building: 4/4 (jakt__prelude__string.cpp)
Error: Compilation failed

Not sure on a workaround just yet.

Cheers,

Hugh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions