Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-5719

Unused property hint shown when used to instantiate an anonymous class

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 12.4
    • 12.5
    • php - Editor
    • Product Version: Apache NetBeans IDE 12.4
      Java: 15.0.2; OpenJDK 64-Bit Server VM 15.0.2+7-27
      Runtime: OpenJDK Runtime Environment 15.0.2+7-27

    Description

      If a class property is used only to create an instance of an anonymous class, it is marked with an 'Unused' hint.

      The example code is below. There is also an image attached with a screenshot, note how $anyParameter in Factory1 constructor is underlined. This goes for both constructor argument promotion and the PHP7-style property declaration.
       

      <?php declare(strict_types = 1);
      
      namespace Cz\Test\UsedProperty;
      
      class Factory1
      {
          public function __construct(private bool $anyParameter)
          {
          }
      
          public function create(): Interface1
          {
              return new class ($this->anyParameter) implements Interface1
              {
                  public function __construct(private bool $parameter1)
                  {
                  }
      
                  public function getSomeParameter(): bool
                  {
                      return $this->parameter1;
                  }
              };
          }
      }
      
      
      interface Interface1
      {
          function getSomeParameter(): bool;
      }
      
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            junichi11 Junichi Yamamoto
            czukowski Czukowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1.5h
                1.5h

                Slack

                  Issue deployment