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 reference to itself in a tuple fails compilation in C++ #1325

Open
hughdavenport opened this issue Jan 18, 2023 · 0 comments
Open

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

hughdavenport opened this issue Jan 18, 2023 · 0 comments

Comments

@hughdavenport
Copy link

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

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

No branches or pull requests

1 participant