Skip to content

Commit a996a1d

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 0142560 + 6780f3d commit a996a1d

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ ERROR(reserved_member_name,none,
783783
"type member must not be named %0, since it would conflict with the"
784784
" 'foo.%1' expression", (DeclName, StringRef))
785785

786+
NOTE(invalid_redecl_by_optionality_note,none,
787+
"%select{implicitly unwrapped |}0optional parameter is of "
788+
"same type as %select{implicitly unwrapped |}1optional parameter",
789+
(bool, bool))
786790
ERROR(invalid_redecl,none,"invalid redeclaration of %0", (DeclName))
787791
ERROR(invalid_redecl_init,none,
788792
"invalid redeclaration of synthesized %select{|memberwise }1%0",

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,66 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
646646
continue;
647647
}
648648

649+
// Signatures are the same, but interface types are not. We must
650+
// have a type that we've massaged as part of signature
651+
// interface type generation.
652+
if (current->getInterfaceType()->isEqual(other->getInterfaceType())) {
653+
if (currentDC->isTypeContext() == other->getDeclContext()->isTypeContext()) {
654+
auto currFnTy = current->getInterfaceType()->getAs<AnyFunctionType>();
655+
auto otherFnTy = other->getInterfaceType()->getAs<AnyFunctionType>();
656+
if (currFnTy && otherFnTy && currentDC->isTypeContext()) {
657+
currFnTy = currFnTy->getResult()->getAs<AnyFunctionType>();
658+
otherFnTy = otherFnTy->getResult()->getAs<AnyFunctionType>();
659+
}
660+
661+
if (currFnTy && otherFnTy) {
662+
ArrayRef<AnyFunctionType::Param> currParams = currFnTy->getParams();
663+
ArrayRef<AnyFunctionType::Param> otherParams = otherFnTy->getParams();
664+
665+
if (currParams.size() == otherParams.size()) {
666+
auto diagnosed = false;
667+
for (unsigned i : indices(currParams)) {
668+
669+
bool currIsIUO = false;
670+
bool otherIsIUO = false;
671+
bool optionalRedecl = false;
672+
673+
if (currParams[i].getPlainType()->getOptionalObjectType()) {
674+
optionalRedecl = true;
675+
if (swift::getParameterAt(current, i)->isImplicitlyUnwrappedOptional())
676+
currIsIUO = true;
677+
}
678+
679+
if (otherParams[i].getPlainType()->getOptionalObjectType()) {
680+
if (swift::getParameterAt(other, i)->isImplicitlyUnwrappedOptional())
681+
otherIsIUO = true;
682+
}
683+
else {
684+
optionalRedecl = false;
685+
}
686+
687+
if (optionalRedecl && currIsIUO != otherIsIUO) {
688+
ctx.Diags.diagnoseWithNotes(
689+
current->diagnose(diag::invalid_redecl,
690+
current->getName()), [&]() {
691+
other->diagnose(diag::invalid_redecl_prev, other->getName());
692+
});
693+
current->diagnose(diag::invalid_redecl_by_optionality_note,
694+
otherIsIUO, currIsIUO);
695+
696+
current->setInvalid();
697+
diagnosed = true;
698+
break;
699+
}
700+
}
701+
702+
if (diagnosed)
703+
break;
704+
}
705+
}
706+
}
707+
}
708+
649709
// If the conflicting declarations have non-overlapping availability and,
650710
// we allow the redeclaration to proceed if...
651711
//

stdlib/tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ makeLocalSection(const void *Buffer,
310310
}
311311

312312
swift_reflection_section_t LS = {(void *)Buffer,
313-
(void *)(Buffer + Section.Size)};
313+
(void *)((uint8_t *)Buffer + Section.Size)};
314314
return LS;
315315
}
316316

test/Interop/Cxx/value-witness-table/witness-layout-opts-irgen.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// to test them in the same file.
88
// XFAIL: OS=windows-msvc
99

10+
// Failing on 32-bit simulator, disable for now. rdar://73829982
11+
// REQUIRES: rdar73829982
12+
1013
import WitnessLayoutOpts
1114

1215
protocol Dummy { }

test/Sema/diag_erroneous_iuo.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func overloadedByOptionality(_ a: inout Int!) {}
211211
// expected-note@-1 {{'overloadedByOptionality' previously declared here}}
212212
func overloadedByOptionality(_ a: inout Int?) {}
213213
// expected-error@-1 {{invalid redeclaration of 'overloadedByOptionality'}}
214+
// expected-note@-2 {{optional parameter is of same type as implicitly unwrapped optional parameter}}
214215

215216
struct T {
216217
let i: Int!

test/decl/overload.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,25 @@ func inout2(x: inout Int) { }
379379

380380
// optionals
381381
func optional(x: Int?) { } // expected-note{{previously declared}}
382-
func optional(x: Int!) { } // expected-error{{invalid redeclaration of 'optional(x:)'}}
382+
func optional(x: Int!) { }
383+
// expected-error@-1{{invalid redeclaration of 'optional(x:)'}}
384+
// expected-note@-2 {{implicitly unwrapped optional parameter is of same type as optional parameter}}
383385

384386
func optionalInOut(x: inout Int?) { } // expected-note{{previously declared}}
385-
func optionalInOut(x: inout Int!) { } // expected-error{{invalid redeclaration of 'optionalInOut(x:)}}
387+
func optionalInOut(x: inout Int!) { }
388+
// expected-error@-1{{invalid redeclaration of 'optionalInOut(x:)'}}
389+
// expected-note@-2 {{implicitly unwrapped optional parameter is of same type as optional parameter}}
386390

387391
class optionalOverloads {
388392
class func optionalInOut(x: inout Int?) { } // expected-note{{previously declared}}
389-
class func optionalInOut(x: inout Int!) { } // expected-error{{invalid redeclaration of 'optionalInOut(x:)'}}
393+
class func optionalInOut(x: inout Int!) { }
394+
// expected-error@-1{{invalid redeclaration of 'optionalInOut(x:)'}}
395+
// expected-note@-2 {{implicitly unwrapped optional parameter is of same type as optional parameter}}
390396

391397
func optionalInOut(x: inout Int?) { } // expected-note{{previously declared}}
392-
func optionalInOut(x: inout Int!) { } // expected-error{{invalid redeclaration of 'optionalInOut(x:)}}
398+
func optionalInOut(x: inout Int!) { }
399+
// expected-error@-1{{invalid redeclaration of 'optionalInOut(x:)'}}
400+
// expected-note@-2 {{implicitly unwrapped optional parameter is of same type as optional parameter}}
393401
}
394402

395403
func optional_3() -> Int? { } // expected-note{{previously declared}}

0 commit comments

Comments
 (0)