Commit Graph

10 Commits

Author SHA1 Message Date
Becca Royal-Gordon
8c9a6ce0b4 Increase determinism of selector conflict errors
Refactor ObjC conflict diagnosis code to sort conflict data more thoroughly, filter out unwanted declarations earlier, and just generally behave in ways that are more likely to work correctly.

This change increases the determinism of the ordering of diagnostics and the selection of the “correct” declaration that the others are considered to conflict with, increasing my confidence that the diagnostics will work correctly in untested corner cases or if the compiler is refactored so that declarations are recorded in a different order. It also adds a new selection rule—@objc without vs. with explicit selector—that I believe will slightly improve the diagnostics we produce. And it replaces a lot of really dodgy-looking logic that may have only worked reliably when a conflict involved exactly two methods.
2022-06-28 18:15:54 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Jordan Rose
e5b8ff9e84 Continue tweaking the wording of the ObjC selector conflict diagnostics.
Per feedback from Doug. More rdar://problem/19927828

Swift SVN r25740
2015-03-04 02:25:04 +00:00
Jordan Rose
c91952130f Wordsmith the errors for Objective-C selector conflicts.
Also, if warning about an accessor that comes from a stored property,
point to the property rather than the (implicit, source-location-less)
accessor decl.

Both of these changes are aimed at improving the presentation in Xcode.

rdar://problem/19927828

Swift SVN r25725
2015-03-03 23:25:46 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Doug Gregor
2fc0ce6b40 Bias Objective-C method redeclaration diagnostics toward methods in the class.
Specifically, when a method defined in the class itself conflicts with
a method defined in an extension of the class, consider the method
defined in the class to be the original declaration (and complain
about the others). This is just QoI that improves predictability, and
is part of rdar://problem/18391046.

Swift SVN r23197
2014-11-09 06:35:20 +00:00
Doug Gregor
b3badc601a Handle consistency checking that requires the entire module.
Objective-C method unintended override checking is one such case where
properly checking unintended overrides requires us to essentially look
at the whole module, because one translation unit may declare
something that produces an Objective-C method "setFoo:" in a
superclass while another translation unit declares something with a
distinct name that produces an Objective-C method "setFoo:". So, when
we don't have a primary file (e.g., when we're doing the merge-module
step), delay such checks until after all the source files for the
module have been type-checked. When there is a primary file, we
perform the checking that we can based on type checking that primary
file (and whatever got touched along the way), so we get a subset of
the proper diagnostics.

Swift SVN r23179
2014-11-08 06:20:57 +00:00
Doug Gregor
3df2c11c8a Diagnose Objective-C method overrides not reflected as Swift overrides.
Diagnose cases where the use of @objc will produce Objective-C methods
that end up overriding an Objective-C method in a superclass, when
that override is not properly represented as an override in the Swift
type system. This can happen when the Objective-C methods are produced
by different kinds of entities. For example:

  class Super {
    @objc var property: Int
  }

  class Sub : Super {
    @objc func setProperty(property: Int) { }
  }

In Swift, Sub.setProperty and Super.property are completely
unrelated. However, both produce an Objective-C instance method with
the selector "setProperty:", so we end up with unexpected overriding
behavior. Diagnose this whenever it occurs, regardless of the kind of
@objc entity that produced the Objective-C methods: initializers,
deinitializers, methods, properties, or subscripts.

Implements the rest of the intended functionality of
rdar://problem/18391046, with the caveat that there are two remaining
classes of bugs:
  1) Superclasses defined in a module (or imported from a Clang
  module) aren't handled properly yet; we might not see those methods.
  2) We won't properly detect all of these failures when the methods
  are scattered across different source files in the same module.

Swift SVN r23170
2014-11-08 00:55:45 +00:00
Doug Gregor
89e5e5b6fa Diagnose redeclarations of Objective-C methods.
@objc methods, initializers, deinitializers, properties, and
subscripts all produce Objective-C methods. Diagnose cases where two
such entities (which may be of different kinds) produce the same
Objective-C method in the same class.

As a special exception, one can have an Objective-C method in an
extension that conflicts with an Objective-C method in the original
class definition, so long as the original class definition is from a
different model. This reflects the reality in Objective-C that the
category definition wins over the original definition, and is used in
at least one overlay (SpriteKit).

This is the first part of rdar://problem/18391046; the second part
involves checking that overrides are sane.

Swift SVN r23147
2014-11-07 01:15:14 +00:00