Skip to content

[xtro] Fix checking availability on categories. - #2682

Merged
spouliot merged 1 commit into
dotnet:xcode9from
rolfbjarne:xtro-fix-category-availability
Sep 13, 2017
Merged

[xtro] Fix checking availability on categories.#2682
spouliot merged 1 commit into
dotnet:xcode9from
rolfbjarne:xtro-fix-category-availability

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

When checking for category availability, check if both the current declaration
is a category, and if the current's declaration container is a category.

Otherwise this scenario fails:

  • Category method is available.
  • Category does not have availability attributes.
  • Main class is unavailable.

with this typical code sequence:

// don't process methods (or types) that are unavailable for the current platform
if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
	return;

In which case we'd:

  • First check the method (decl):

    • It's available, so no further checks is done on the method.
  • Then we'd check the method's container (decl.DeclContext):

    • The container (the category) does not have availability attributes.
    • Then we'd check if the container's container is a category (it isn't, it's the namespace).

and as such determine that the method is available.

With this change, the second step will become:

  • Then we'd check the method's container (decl.DeclContext):
    • The container (the category) does not have availability attributes.
    • Then we'd check if the container is a category (it is), and if its main class is available (it isn't).

and as such determine that the method is unavailable.

  • Check for attributes on the method's container (no attributes, so we continue).
  • Check if the method's

Unclassified diff: https://gist.github.com/rolfbjarne/8fa80962596978a426eadf9b7ba39dc1

When checking for category availability, check if both the current declaration
is a category, and if the current's declaration container is a category.

Otherwise this scenario fails:

* Category method is available.
* Category does not have availability attributes.
* Main class is unavailable.

with this typical code sequence:

```csharp
// don't process methods (or types) that are unavailable for the current platform
if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
	return;
```

In which case we'd:

* First check the method (`decl`):
	* It's available, so no further checks is done on the method.

* Then we'd check the method's container (`decl.DeclContext`):
	* The container (the category) does not have availability attributes.
	* Then we'd check if the container's container is a category (it isn't, it's the namespace).

and as such determine that the method is available.

With this change, the second step will become:

* Then we'd check the method's container (`decl.DeclContext`):
	* The container (the category) does not have availability attributes.
	* Then we'd check if the container is a category (it is), and if its main class is available (it isn't).

and as such determine that the method is unavailable.

* Check for attributes on the method's container (no attributes, so we continue).
* Check if the method's

Unclassified diff: https://gist.github.com/rolfbjarne/8fa80962596978a426eadf9b7ba39dc1

@spouliot spouliot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@spouliot

Copy link
Copy Markdown
Contributor

merging right now as this is not executed on bots

@spouliot
spouliot merged commit 8a21e57 into dotnet:xcode9 Sep 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants