Skip to content

Commit ed168d9

Browse files
author
Omar Habra
committed
adding tests
1 parent 21cc043 commit ed168d9

File tree

6 files changed

+161
-70
lines changed

6 files changed

+161
-70
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,6 +3656,7 @@ namespace {
36563656
}
36573657

36583658
result->setMemberLoader(&Impl, 0);
3659+
result->dump();
36593660
return result;
36603661
}
36613662

@@ -4413,8 +4414,7 @@ namespace {
44134414
// Find if we have a getter.
44144415
auto pred = [](auto attr) {
44154416
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr)) {
4416-
return swiftAttr->getAttribute() == "import_as_getter" ||
4417-
swiftAttr->getAttribute() == "import_as_setter";
4417+
return swiftAttr->getAttribute() == "import_as_getter";
44184418
}
44194419
return false;
44204420
// for setter
@@ -4449,14 +4449,14 @@ namespace {
44494449
if (!dc)
44504450
return nullptr;
44514451

4452-
auto importedType =
4453-
Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4454-
isInSystemModule(dc), Bridgeability::None);
4455-
if (!importedType)
4456-
return nullptr;
4457-
4458-
auto type = importedType.getType();
4459-
auto It = Impl.GetterSetterMap.find(name);
4452+
// auto importedType =
4453+
// Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4454+
// isInSystemModule(dc), Bridgeability::None);
4455+
// if (!importedType)
4456+
// return nullptr;
4457+
//
4458+
// auto type = importedType.getType();
4459+
// auto It = Impl.GetterSetterMap.find(name);
44604460

44614461
Impl.GetterSetterMap[name].first = static_cast<FuncDecl *>(method);
44624462
// store the cxx methods then generate the property accessors
@@ -4481,14 +4481,14 @@ namespace {
44814481
if (!dc)
44824482
return nullptr;
44834483

4484-
auto importedType =
4485-
Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4486-
isInSystemModule(dc), Bridgeability::None);
4487-
if (!importedType)
4488-
return nullptr;
4489-
4490-
auto type = importedType.getType();
4491-
auto It = Impl.GetterSetterMap.find(name);
4484+
// auto importedType =
4485+
// Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4486+
// isInSystemModule(dc), Bridgeability::None);
4487+
// if (!importedType)
4488+
// return nullptr;
4489+
//
4490+
// auto type = importedType.getType();
4491+
// auto It = Impl.GetterSetterMap.find(name);
44924492

44934493
Impl.GetterSetterMap[name].second = static_cast<FuncDecl *>(method);
44944494
// store the cxx methods then generate the property accessors
@@ -7964,11 +7964,12 @@ VarDecl *SwiftDeclConverter::makeProperty(Identifier identifier, FuncDecl *gette
79647964

79657965
// VarDecl::createImported(ctx, name, )
79667966
auto &ctx = Impl.SwiftContext;
7967-
DeclName name(ctx, DeclBaseName(identifier), {});
7967+
// DeclName name(identifier);
79687968
auto dc = getter->getDeclContext();
79697969

7970-
auto result = VarDecl::createImported(ctx, name, getter->getStartLoc(), getter->getStartLoc(), getter->getInterfaceType(), dc, getter->getClangNode());
7970+
auto result = VarDecl::createImported(ctx, identifier, getter->getStartLoc(), getter->getStartLoc(), getter->getResultInterfaceType(), dc, getter->getClangNode());
79717971
result->setAccess(AccessLevel::Public);
7972+
result->setImplInfo(StorageImplInfo::getMutableComputed());
79727973

79737974
AccessorDecl *getterDecl = AccessorDecl::create(ctx,
79747975
getter->getLoc(),
@@ -7979,7 +7980,8 @@ VarDecl *SwiftDeclConverter::makeProperty(Identifier identifier, FuncDecl *gette
79797980
StaticSpellingKind::None,
79807981
/*async*/ false, SourceLoc(),
79817982
/*throws*/ false, SourceLoc(),
7982-
nullptr, {},
7983+
nullptr,
7984+
ParameterList::createEmpty(ctx),
79837985
getter->getResultInterfaceType(),
79847986
dc);
79857987
getterDecl->setAccess(AccessLevel::Public);

lib/IRGen/GenStruct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ class ClangRecordLowering {
10531053
addStructField(clangField, swiftField);
10541054
}
10551055

1056-
assert(sfi == sfe && "more Swift fields than there were Clang fields?");
1056+
// assert(sfi == sfe && "more Swift fields than there were Clang fields?");
10571057

10581058
// We never take advantage of tail padding, because that would prevent
10591059
// us from passing the address of the object off to C, which is a pretty

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,8 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
24142414
break;
24152415
}
24162416
}
2417+
if (storage->hasClangNode())
2418+
break;
24172419
if (auto subscript = dyn_cast<SubscriptDecl>(storage)) {
24182420
break;
24192421
}

test/Interop/Cxx/ergonomics/Inputs/implicit-computed-properties.h

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,59 @@
11
#ifndef SWIFT_IMPLICIT_COMPUTED_PROPERTIES_H
22
#define SWIFT_IMPLICIT_COMPUTED_PROPERTIES_H
33

4-
//struct VoidGetter {
5-
// void getX();
6-
// void setX(int);
7-
//};
8-
9-
//struct VoidGetterNoName {
10-
// void set();
11-
//};
12-
//
13-
//struct IllegalIntReturnSetter {
14-
// int setX(int);
15-
//};
16-
17-
//struct TwoParameterSetter {
18-
// void setX(int, int);
19-
//};
20-
21-
//struct NoNameSetter {
22-
// void set(int);
23-
//};
24-
25-
//struct NoNameVoidGetter {
26-
// void get();
27-
//
28-
//};
29-
//
30-
//struct LongNameAllLower {
31-
// int getfoo();
32-
//};
33-
//
34-
//struct LongNameAllUpper {
35-
// int getFOO();
36-
//};
37-
//
38-
//struct LongNameMix {
39-
// int GetFoo();
40-
//};
41-
//
42-
//struct NoNameUpperGetter {
43-
// int Getter();
44-
//};
45-
//
46-
////struct NotypeSetter {
47-
//// void setX();
48-
////};
4+
struct VoidGetter {
5+
void getX();
6+
void setX(int);
7+
};
8+
9+
struct VoidGetterNoName {
10+
void set();
11+
};
12+
13+
struct IllegalIntReturnSetter {
14+
int setX(int);
15+
};
16+
17+
struct TwoParameterSetter {
18+
void setX(int, int);
19+
};
20+
21+
struct NoNameSetter {
22+
void set(int);
23+
};
24+
25+
struct NoNameVoidGetter {
26+
void get();
27+
28+
};
29+
30+
struct LongNameAllLower {
31+
int getfoo() { return 42; }
32+
33+
};
34+
35+
struct LongNameAllUpper {
36+
int getFOO() { return 42; }
37+
};
38+
39+
struct LongNameMix {
40+
int GetFoo(){ return 42; }
41+
};
42+
43+
struct GetterOnly {
44+
int getFoo() { return 42; }
45+
};
46+
47+
struct NoNameUpperGetter {
48+
int Getter();
49+
};
50+
51+
struct NotypeSetter {
52+
void setX();
53+
};
4954

5055
struct IntGetterSetter {
51-
// int getX() const {}
56+
int getX() const {}
5257
void setX(int) {}
5358
};
5459

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=ImplicitComputedProperties -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
22

3+
//CHECK: struct VoidGetter {
4+
//CHECK-NEXT: init()
5+
//CHECK-NEXT: mutating func getX()
6+
//CHECK-NEXT: mutating func setX(_: Int32)
7+
//CHECK-NEXT: }
8+
9+
//CHECK: struct VoidGetterNoName {
10+
//CHECK-NEXT: init()
11+
//CHECK-NEXT: mutating func set()
12+
//CHECK-NEXT:}
13+
14+
//CHECK: struct IllegalIntReturnSetter {
15+
//CHECK-NEXT: init()
16+
//CHECK-NEXT: mutating func setX(_: Int32) -> Int32
17+
//CHECK-NEXT: }
18+
19+
//CHECK: struct TwoParameterSetter {
20+
//CHECK-NEXT: init()
21+
//CHECK-NEXT: mutating func setX(_: Int32, _: Int32)
22+
//CHECK-NEXT: }
23+
24+
//CHECK: struct NoNameSetter {
25+
//CHECK-NEXT: init()
26+
//CHECK-NEXT: mutating func set(_: Int32)
27+
//CHECK-NEXT: }
28+
29+
//CHECK: struct NoNameVoidGetter {
30+
//CHECK-NEXT: init()
31+
//CHECK-NEXT: mutating func get()
32+
//CHECK-NEXT: }
33+
34+
//CHECK: struct LongNameAllLower {
35+
//CHECK-NEXT: init()
36+
//CHECK-NEXT: mutating func getfoo() -> Int32
37+
//CHECK-NEXT: }
38+
39+
//CHECK: struct LongNameAllUpper {
40+
//CHECK-NEXT: init()
41+
//CHECK-NEXT: mutating func getFOO() -> Int32
42+
//CHECK-NEXT: }
43+
44+
//CHECK: struct LongNameMix {
45+
//CHECK-NEXT: init()
46+
//CHECK-NEXT: mutating func GetFoo() -> Int32
47+
//CHECK-NEXT: }
48+
49+
//CHECK: struct NoNameUpperGetter {
50+
//CHECK-NEXT: init()
51+
//CHECK-NEXT: mutating func Getter() -> Int32
52+
//CHECK-NEXT: }
53+
54+
//CHECK: struct NotypeSetter {
55+
//CHECK-NEXT: init()
56+
//CHECK-NEXT: mutating func setX()
57+
//CHECK-NEXT: }
58+
59+
//CHECK: struct IntGetterSetter {
60+
//CHECK-NEXT: init()
61+
//CHECK-NEXT: func getX() -> Int32
62+
//CHECK-NEXT: mutating func setX(_: Int32)
63+
//CHECK-NEXT: }

test/Interop/Cxx/ergonomics/implicit-computed-properties.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,35 @@ import ImplicitComputedProperties
77

88
var ImplicitComputedPropertiesTestSuite = TestSuite("ImplicitComputedProperties")
99

10-
ImplicitComputedPropertiesTestSuite.test("getters") {
10+
ImplicitComputedPropertiesTestSuite.test("LongNameAllLower") {
11+
var VoidGetter = LongNameAllLower()
12+
13+
expectEqual(VoidGetter.get, 42)
14+
15+
}
16+
ImplicitComputedPropertiesTestSuite.test("LongNameAllUpper") {
17+
var VoidGetter = LongNameAllUpper()
18+
19+
expectEqual(VoidGetter.get, 42)
20+
21+
}
22+
ImplicitComputedPropertiesTestSuite.test("LongNameMix") {
23+
var VoidGetter = LongNameMix()
24+
25+
expectEqual(VoidGetter.get, 42)
26+
27+
}
28+
ImplicitComputedPropertiesTestSuite.test("GetterOnly") {
29+
var VoidGetter = GetterOnly()
30+
31+
expectEqual(VoidGetter.get, 42)
1132

1233
}
1334

1435
ImplicitComputedPropertiesTestSuite.test("setters") {
1536
var Object = X()
1637
Object.x = 1
17-
1838
expectEqual(Object.x, 1)
1939
}
40+
2041
runAllTests()

0 commit comments

Comments
 (0)