Skip to content

Add nested generic LLDB metadata tests #5579

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 1 commit into from
Nov 11, 2022
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
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class SwiftGenericClassNestedInFunctionTest(TestBase):

@swiftTest
def test(self):
"""Tests that a generic class type nested inside a function 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 self", substrs=["B<Int>"])

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This test was created to ensure that the changes in in: apple/swift#61819 did not break behaviour.

func a() {
class B<T>{
func f() {
print(1) // break here
}
}
B<Int>().f()
}
a()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class SwiftGenericClassInHashedContainerTest(TestBase):

@swiftTest
def test(self):
"""Tests that the type of hashed container whose value type is a non-generic class declared inside a generic class can be read from instance metadata"""
self.build()
lldbutil.run_to_source_breakpoint(self,"break here", lldb.SBFileSpec("main.swift"))
self.expect("v val", substrs=["(a.A<Int>.B) val"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class A<T> {
public func addValue() {
self.dict["key"] = B()
}
private class B {}
private var dict: [String: B] = [:]
func test() {
let val = dict["key"]!
print(1) // break here
}
}

let foo = A<Int>()
foo.addValue()
foo.test()

2 changes: 2 additions & 0 deletions lldb/test/API/lang/swift/nested_generic_class/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class SwiftNestedGenericClassTest(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>"])

7 changes: 7 additions & 0 deletions lldb/test/API/lang/swift/nested_generic_class/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class A<T> {
public class B<U> {
}
}

let foo = A<Int>.B<String>()
print(1) // break here
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class SwiftPrivateNestedGenericClassTest(TestBase):

@swiftTest
def test(self):
"""Tests that a private 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 self", substrs=["A<Int>.B<String>"])
12 changes: 12 additions & 0 deletions lldb/test/API/lang/swift/private_nested_generic_class/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class A<T> {
private class B<U> {
func f() {
print(1) // break here
}
}
func g() {
B<String>().f()
}
}

A<Int>().g()