Skip to content

[lldb] Add more test cases to TestSwiftNestedGenericClass #5940

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1644,8 +1644,13 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
Log *log(GetLog(LLDBLog::Types));
auto *reflection_ctx = GetReflectionContext();
const auto *typeref = reflection_ctx->readTypeFromInstance(instance_ptr);
if (!typeref)
if (!typeref) {
if (log) {
log->Printf("could not read typeref for type: %s\n",
class_type.GetMangledTypeName().GetCString());
}
return false;
}
swift::Demangle::Demangler dem;
swift::Demangle::NodePointer node = typeref->getDemangling(dem);
class_type_or_name.SetCompilerType(ts.RemangleAsType(dem, node));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
import unittest2


class SwiftNestedGenericClassTest(TestBase):
class TestSwiftNestedGenericClass(TestBase):

@swiftTest
def test(self):
"""Tests that a generic class type nested inside another generic class can be resolved correctly from the instance metadata"""
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.swift"))
self.expect("v foo", substrs=["a.A<Int>.B<String>"])
_, process, _, breakpoint = lldbutil.run_to_source_breakpoint(self,
"break here", lldb.SBFileSpec("main.swift"))
self.expect("v self", substrs=["A<Int>.B<String>"])

lldbutil.continue_to_breakpoint(process, breakpoint)
self.expect("v self", substrs=["C.D<Double>"])

lldbutil.continue_to_breakpoint(process, breakpoint)
self.expect("v self", substrs=["F.G<Bool>.H"])

lldbutil.continue_to_breakpoint(process, breakpoint)
self.expect("v self", substrs=["I.J<String, Int>"])


lldbutil.continue_to_breakpoint(process, breakpoint)
self.expect("v self", substrs=["K.L.M<Double, Bool>"])

46 changes: 44 additions & 2 deletions lldb/test/API/lang/swift/nested_generic_class/main.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
public class A<T> {
public class B<U> {
func f() {
print(1) // break here
}
}
}

let foo = A<Int>.B<String>()
print(1) // break here
class C {
class D<T> {
func f() {
print(1) // break here
}
}
}

class F {
class G<T> {
class H {
func f() {
print(1) // break here
}
}
}
}

class I {
class J<T, U> {
func f() {
print(1) // break here
}
}
}

class K {
class L {
class M<T, U> {
func f() {
print(1) // break here
}
}
}
}

A<Int>.B<String>().f()
C.D<Double>().f()
F.G<Bool>.H().f()
I.J<String, Int>().f()
K.L.M<Double, Bool>().f()