Skip to content

Commit 28c3a07

Browse files
author
Omar Habra
committed
adding tests
1 parent 749b87e commit 28c3a07

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
@@ -3627,6 +3627,7 @@ namespace {
36273627
}
36283628

36293629
result->setMemberLoader(&Impl, 0);
3630+
result->dump();
36303631
return result;
36313632
}
36323633

@@ -4365,8 +4366,7 @@ namespace {
43654366
// Find if we have a getter.
43664367
auto pred = [](auto attr) {
43674368
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr)) {
4368-
return swiftAttr->getAttribute() == "import_as_getter" ||
4369-
swiftAttr->getAttribute() == "import_as_setter";
4369+
return swiftAttr->getAttribute() == "import_as_getter";
43704370
}
43714371
return false;
43724372
// for setter
@@ -4401,14 +4401,14 @@ namespace {
44014401
if (!dc)
44024402
return nullptr;
44034403

4404-
auto importedType =
4405-
Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4406-
isInSystemModule(dc), Bridgeability::None);
4407-
if (!importedType)
4408-
return nullptr;
4409-
4410-
auto type = importedType.getType();
4411-
auto It = Impl.GetterSetterMap.find(name);
4404+
// auto importedType =
4405+
// Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4406+
// isInSystemModule(dc), Bridgeability::None);
4407+
// if (!importedType)
4408+
// return nullptr;
4409+
//
4410+
// auto type = importedType.getType();
4411+
// auto It = Impl.GetterSetterMap.find(name);
44124412

44134413
Impl.GetterSetterMap[name].first = static_cast<FuncDecl *>(method);
44144414
// store the cxx methods then generate the property accessors
@@ -4433,14 +4433,14 @@ namespace {
44334433
if (!dc)
44344434
return nullptr;
44354435

4436-
auto importedType =
4437-
Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4438-
isInSystemModule(dc), Bridgeability::None);
4439-
if (!importedType)
4440-
return nullptr;
4441-
4442-
auto type = importedType.getType();
4443-
auto It = Impl.GetterSetterMap.find(name);
4436+
// auto importedType =
4437+
// Impl.importType(decl->getReturnType(), ImportTypeKind::Result,
4438+
// isInSystemModule(dc), Bridgeability::None);
4439+
// if (!importedType)
4440+
// return nullptr;
4441+
//
4442+
// auto type = importedType.getType();
4443+
// auto It = Impl.GetterSetterMap.find(name);
44444444

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

79177917
// VarDecl::createImported(ctx, name, )
79187918
auto &ctx = Impl.SwiftContext;
7919-
DeclName name(ctx, DeclBaseName(identifier), {});
7919+
// DeclName name(identifier);
79207920
auto dc = getter->getDeclContext();
79217921

7922-
auto result = VarDecl::createImported(ctx, name, getter->getStartLoc(), getter->getStartLoc(), getter->getInterfaceType(), dc, getter->getClangNode());
7922+
auto result = VarDecl::createImported(ctx, identifier, getter->getStartLoc(), getter->getStartLoc(), getter->getResultInterfaceType(), dc, getter->getClangNode());
79237923
result->setAccess(AccessLevel::Public);
7924+
result->setImplInfo(StorageImplInfo::getMutableComputed());
79247925

79257926
AccessorDecl *getterDecl = AccessorDecl::create(ctx,
79267927
getter->getLoc(),
@@ -7931,7 +7932,8 @@ VarDecl *SwiftDeclConverter::makeProperty(Identifier identifier, FuncDecl *gette
79317932
StaticSpellingKind::None,
79327933
/*async*/ false, SourceLoc(),
79337934
/*throws*/ false, SourceLoc(),
7934-
nullptr, {},
7935+
nullptr,
7936+
ParameterList::createEmpty(ctx),
79357937
getter->getResultInterfaceType(),
79367938
dc);
79377939
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
@@ -2412,6 +2412,8 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
24122412
break;
24132413
}
24142414
}
2415+
if (storage->hasClangNode())
2416+
break;
24152417
if (auto subscript = dyn_cast<SubscriptDecl>(storage)) {
24162418
break;
24172419
}

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)