Skip to content

Fix the TypeChecker's omitNeedlessWords to use interface types. #7212

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
8 changes: 4 additions & 4 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3548,7 +3548,7 @@ Optional<DeclName> TypeChecker::omitNeedlessWords(AbstractFunctionDecl *afd) {

// Always look at the parameters in the last parameter list.
for (auto param : *afd->getParameterLists().back()) {
paramTypes.push_back(getTypeNameForOmission(param->getType())
paramTypes.push_back(getTypeNameForOmission(param->getInterfaceType())
.withDefaultArgument(param->isDefaultArgument()));
}

Expand Down Expand Up @@ -3616,10 +3616,10 @@ Optional<DeclName> TypeChecker::omitNeedlessWords(AbstractFunctionDecl *afd) {
Optional<Identifier> TypeChecker::omitNeedlessWords(VarDecl *var) {
auto &Context = var->getASTContext();

if (!var->hasType())
if (!var->hasInterfaceType())
validateDecl(var);

if (var->isInvalid() || !var->hasType())
if (var->isInvalid() || !var->hasInterfaceType())
return None;

if (var->getName().empty())
Expand Down Expand Up @@ -3650,7 +3650,7 @@ Optional<Identifier> TypeChecker::omitNeedlessWords(VarDecl *var) {

// Omit needless words.
StringScratchSpace scratch;
OmissionTypeName typeName = getTypeNameForOmission(var->getType());
OmissionTypeName typeName = getTypeNameForOmission(var->getInterfaceType());
OmissionTypeName contextTypeName = getTypeNameForOmission(contextType);
if (::omitNeedlessWords(name, { }, "", typeName, contextTypeName, { },
/*returnsSelf=*/false, true, allPropertyNames,
Expand Down
27 changes: 27 additions & 0 deletions validation-test/Sema/protocol_typo_correction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-swift-frontend -emit-module -D LIB %s -o %t/Lib.swiftmodule
// RUN: %target-swift-frontend -I %t -typecheck %s -verify
// REQUIRES: objc_interop

#if LIB

import Foundation

@objc public protocol Proto {
@objc optional func method(_: Int, for object: NSObject, dividing double: Double)
}

#else

import Foundation
import Lib

class Impl: Proto {
func methodWithInt(_: Int, forObject object: NSObject, dividingDouble: Double) { }
// expected-warning@-1 {{instance method 'methodWithInt(_:forObject:dividingDouble:)' nearly matches optional requirement 'method(_:for:dividing:)' of protocol 'Proto'}}
// expected-note@-2{{rename to 'method(_:for:dividing:)' to satisfy this requirement}}{{8-21=method}}{{30-39=for}}{{58-58=dividing }}{{none}}
// expected-note@-3{{move 'methodWithInt(_:forObject:dividingDouble:)' to an extension to silence this warning}}
// expected-note@-4{{make 'methodWithInt(_:forObject:dividingDouble:)' private to silence this warning}}{{3-3=private }}
}

#endif