Skip to content
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

PHP: removed built-in type real #7387

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

troizet
Copy link
Collaborator

@troizet troizet commented May 20, 2024

The main purpose of this PR is to fix the situation where NetBeans generates a real type and uses it as a native return type.

In this PR:

This PR is similar to #5294.

@troizet troizet added the PHP [ci] enable extra PHP tests (php/php.editor) label May 20, 2024
@troizet
Copy link
Collaborator Author

troizet commented May 20, 2024

@mbien Can I ask for the tests to be restarted? I don't have the ability to set the label before creating the PR.

@troizet troizet requested a review from junichi11 May 20, 2024 17:27
@apache apache locked and limited conversation to collaborators May 20, 2024
@apache apache unlocked this conversation May 20, 2024
@@ -29,7 +29,7 @@ public class Scalar extends Expression {

public enum Type {
INT, // 'int'
REAL, // 'real'
FLOAT, // 'float'
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should change this because this is an API.

Copy link
Member

@tmysik tmysik May 21, 2024

Choose a reason for hiding this comment

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

Right, we cannot do this if it is an API/SPI. If you really want to do that, the steps should be like:

  • in release X
    • deprecate the REAL type + document all the details (why deprecated and when it will be removed)
    • add new FLOAT type
    • change the code under our control to start using the FLOAT type
    • increase the minor API version of the module
  • in release X + Y (Y is quite a big number, we cannot do it in the near future, we need to give time to our API consumers - plugins - to change their code):
    • remove the REAL type
    • increase the major API version of the module

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tmysik Thank you very much for the explanation.

Updated the PR:

  • removed the real type removal in the public api.
  • increased the minor version of the module.

I hope I did everything correctly.

@junichi11 junichi11 requested a review from tmysik May 20, 2024 22:18
@tmysik
Copy link
Member

tmysik commented May 21, 2024

Note: If we already did something similar in #5294, then it is unfortunate, as I explained above. Ideally, we should revert the API change and follow the steps I described.

OTOH, not sure how many plugins exist that are affected by this change and therefore can be broken. Also, the fix should be easy, but we must avoid of such API changes, definitely.

CC @junichi11

@troizet troizet force-pushed the php_remove_built_in_type_real branch from 64bb08e to 4b884fc Compare June 30, 2024 07:21
@troizet
Copy link
Collaborator Author

troizet commented Jun 30, 2024

Note: If we already did something similar in #5294, then it is unfortunate, as I explained above. Ideally, we should revert the API change and follow the steps I described.

By similarity to #5294, I was referring to the purpose of that PR.
If I understood it correctly, there were no changes to the public api in that PR.

@@ -156,7 +156,7 @@ public void visit(Scalar node) {
if (CancelSupport.getDefault().isCancelled()) {
return;
}
if (node.getScalarType().equals(Scalar.Type.REAL) && node.getStringValue().startsWith(BINARY_PREFIX)) {
if (node.getScalarType().equals(Scalar.Type.FLOAT) && node.getStringValue().startsWith(BINARY_PREFIX)) {
Copy link
Member

Choose a reason for hiding this comment

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

@junichi11 Again, please, verify that we can simply replace REAL -> FLOAT and not keep the both types. Thank you.

Copy link
Member

Choose a reason for hiding this comment

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

It should be OK (I assume all REAL types were replaced with FLOAT in the parser).
But I would keep both types, just in case.

Copy link
Member

Choose a reason for hiding this comment

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

The only use case would be if we had it in the index, right? Otherwise, we should be safe.

But as we agreed, I believe that keeping both types should be super-safe. Once we remove the REAL type, it will be very easy to delete all its usages.

@troizet, could you, please, update this PR? Thanks for understanding, and sorry for any inconveniences, we are trying to be really safe here.

Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

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

Approved, but please wait for the approval by @junichi11. Thank you!

@tmysik tmysik self-requested a review July 2, 2024 15:25
Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

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

See the comments - please, keep the REAL type and add the FLOAT one. Later on, we will remove the REAL type with all its usages.

CC @junichi11

  - deleted the built-in type real
    (php does not have a built-in real type: https://www.php.net/manual/en/language.types.intro.php
    Also see the warning under "Scalar Types": https://www.php.net/manual/en/language.types.declarations.php)
  - fixed broken tests
  - new tests added
  - fixes generation of return type real instead of float for a method when overriding a base class method with an autocomplete
  - fixes generation of return type real instead of float for a function in phpDoc
@troizet troizet force-pushed the php_remove_built_in_type_real branch from 4b884fc to a8c9cd8 Compare July 3, 2024 17:59
@troizet
Copy link
Collaborator Author

troizet commented Jul 4, 2024

Made the suggested corrections.

Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks a lot for this PR!

Copy link
Member

@junichi11 junichi11 left a comment

Choose a reason for hiding this comment

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

Thanks for your work!

@junichi11 junichi11 merged commit a450d0f into apache:master Jul 4, 2024
33 checks passed
@troizet
Copy link
Collaborator Author

troizet commented Jul 5, 2024

@junichi11 Forgot to set milestone for this PR, or is it optional? Thank you!

@matthiasblaesing matthiasblaesing added this to the NB23 milestone Jul 5, 2024
Comment on lines +657 to +659
public void testFunctionGuessingFloatReturnType_01() throws Exception {
checkCompletionDocumentation("testfiles/completion/documentation/functionGuessingFloatReturnType.php", "testFloatReturn^Type_01();", false, "");
}
Copy link
Member

Choose a reason for hiding this comment

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

this test started failing recently on linux. Could this be some kind of race condition where it is sometimes returning a different completion item?

it works fine on windows.

Copy link
Member

Choose a reason for hiding this comment

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

I also noticed it. I'll fix it ASAP. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

It should be fixed in #7553. Sorry for the inconvenience.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot, @junichi11!

Copy link
Member

@mbien mbien Jul 8, 2024

Choose a reason for hiding this comment

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

this was a bit of a dejavu for me but I can't remember where this happened before (groovy? javascript? php?)

what do you think about this change:

diff --git a/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java b/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java
index 4b21823..8eff017 100644
--- a/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java
+++ b/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java
@@ -107,6 +107,7 @@
 import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 import javax.swing.JEditorPane;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentEvent.ElementChange;
@@ -182,6 +183,7 @@
 import org.openide.util.Pair;
 import org.openide.util.lookup.Lookups;
 import org.openide.util.test.MockLookup;
+
 import static org.openide.util.test.MockLookup.setLookup;
 
 /**
@@ -3145,13 +3147,12 @@
                 CodeCompletionResult completionResult = cc.complete(context);
                 List<CompletionProposal> proposals = completionResult.getItems();
 
-                CompletionProposal match = null;
-                for (CompletionProposal proposal : proposals) {
-                    if (proposal.getName().startsWith(itemPrefix)) {
-                        match = proposal;
-                        break;
-                    }
-                }
+                List<CompletionProposal> matched = proposals.stream()
+                                                            .filter(p -> p.getName().startsWith(itemPrefix))
+                                                            .collect(Collectors.toList());
+                assertEquals("more than one item matched the prefix", 1, matched.size());
+                CompletionProposal match = matched.get(0);
+
                 assertNotNull(match);
                 assertNotNull(match.getElement());
 

this would prevent this situation to re-occur, however, this would also cause many other test failures right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mbien @junichi11 I apologize for the problematic tests. Couldn't this also be related to the #6066?

Copy link
Member

Choose a reason for hiding this comment

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

@mbien matched.size() may not be 1.

Copy link
Member

Choose a reason for hiding this comment

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

@troizet Maybe, It is not related to this.

Copy link
Member

Choose a reason for hiding this comment

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

@mbien matched.size() may not be 1.

in that case it needs to be sorted so that it doesn't randomly fail

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the cause is it, I think.

@mbien mbien mentioned this pull request Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants