Adapters should only be destroyable if their adapted type is destroyable (#7271)

Adapters were erroneously satisfying `Core.Destroy` because we were
directly getting the object's representation without consideration for
abstract and adapted types. This change ensures that adapted types'
representations are used instead of the adapter types.
This commit is contained in:
Christopher Di Bella
2026-06-10 00:48:33 +00:00
committed by GitHub
parent c7b60662f7
commit eaf16a5250
25 changed files with 2065 additions and 1620 deletions
@@ -200,6 +200,30 @@ fn EqualWitnesses(p: Wrap(Cpp.PublicDestructor)*) -> Wrap(Cpp.PublicDestructor)*
return p;
}
// --- fail_no_destroy.carbon
library "[[@TEST_NAME]]";
import Cpp library "types.h";
class AdaptNoDestroy {
adapt Cpp.DeletedDestructor;
}
fn Make() -> AdaptNoDestroy;
fn F() {
// CHECK:STDERR: fail_no_destroy.carbon:[[@LINE+8]]:3: error: attempt to use a deleted function [CppInteropParseError]
// CHECK:STDERR: 21 | var _: AdaptNoDestroy = Make();
// CHECK:STDERR: | ^
// CHECK:STDERR: fail_no_destroy.carbon:[[@LINE-12]]:10: in file included here [InCppInclude]
// CHECK:STDERR: ./types.h:23:3: note: '~DeletedDestructor' has been explicitly marked deleted here [CppInteropParseNote]
// CHECK:STDERR: 23 | ~DeletedDestructor() = delete;
// CHECK:STDERR: | ^
// CHECK:STDERR:
var _: AdaptNoDestroy = Make();
}
// CHECK:STDOUT: --- destroy_destroyable.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {