Skip to content

Conversation

@macsux
Copy link
Collaborator

@macsux macsux commented Sep 12, 2024

Clean up all warnings, adjust nullability across solution, treat future warnings as errors

return v.DefaultValue(this, p);
}

#pragma warning disable CS0108
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is all generated code. We could have this warning disabled for all class headers. Would that be OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is due to it it being declared on interface type and CS inheriting from J, as the definition exists on both J and CS. It is essentially complaining that you defined the same class type on both parent interface and child interface. While this is syntactically allowed, it is discouraged and generally you need to use special syntax when you wanna do this deliberately. Interestingly enough MSBuild flags this as a warning (asking for new keyword to be used to ensure this is deliberate) BUT Rider is the opposite, says new keyword is not needed. Since I couldn't reconcile this behavior I just chose to disable it. I don't want to disable it at file level as it will eliminate this check for not just types but members.

I think it requires discussion on best way to handle it.

prolog = prolog.WithMisc(ListUtils.Map(prolog.Misc, el => (Misc?)Visit(el, p)));
prolog = prolog.WithJspDirectives(ListUtils.Map(prolog.JspDirectives, el => (Xml.JspDirective?)Visit(el, p)));
prolog = prolog.WithMisc(prolog.Misc.Map(el => (Misc?)Visit(el, p)));
prolog = prolog.WithJspDirectives(prolog.JspDirectives.Map(el => (Xml.JspDirective?)Visit(el, p)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I only saw you change the use of ListUtils.Map() calls in a few other places.

Since this class (and all other visitors) are generated, we would need some kind of consistent pattern we can use. Also, the thing regarding referential equality on the list when the mapping function doesn't change any elements is really important to preserve.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't change behavior of that method beyond allowing it to be used as extension method and ensuring it doesn't allow nulls to be passed in (since you were returning it as such anyways but return type was non-nullable). See change. . While the method itself doesn't allow change, when used as extension method we can still call it with ?. syntax to skip it's invocation altogether and propagate null forward at the call site, allowing us to maintain null checking rules. The extension method syntax should be used across the board as it's more concise and helps solve this null check issue. We will need to modify the generator

@macsux macsux force-pushed the fix/warnings-cleanup branch from c6ea3e7 to a3b5719 Compare September 17, 2024 18:31
@macsux macsux merged commit 0948d09 into openrewrite:main Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants