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

[Refactoring] Fix constant expressions #43035

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Shadow-Devil
Copy link
Contributor

@Shadow-Devil Shadow-Devil commented Jul 3, 2024

Purpose

Expressions that have been reported by IntelliJ to be constant so they can either be replaced by the constant value or removed entirely (e.g. if(true)).
Closes #43034

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 46.85714% with 93 lines in your changes missing coverage. Please review.

Project coverage is 77.32%. Comparing base (50d8551) to head (ec4016c).
Report is 62 commits behind head on master.

Files with missing lines Patch % Lines
.../ballerina/runtime/internal/TableOmDataSource.java 0.00% 27 Missing ⚠️
.../io/ballerina/cli/task/RunNativeImageTestTask.java 21.73% 16 Missing and 2 partials ⚠️
...ntime/transactions/TransactionResourceManager.java 0.00% 13 Missing ⚠️
...nalang/langserver/common/utils/AnnotationUtil.java 28.57% 2 Missing and 3 partials ⚠️
...ava/io/ballerina/runtime/internal/TypeChecker.java 0.00% 0 Missing and 2 partials ⚠️
...ng/compiler/packaging/converters/URIConverter.java 0.00% 2 Missing ⚠️
.../compiler/semantics/analyzer/DataflowAnalyzer.java 89.47% 1 Missing and 1 partial ⚠️
...alang/compiler/semantics/analyzer/TypeChecker.java 60.00% 1 Missing and 1 partial ⚠️
...rina/compiler/internal/parser/BallerinaParser.java 75.00% 1 Missing and 1 partial ⚠️
.../ballerina/runtime/internal/JsonInternalUtils.java 0.00% 0 Missing and 1 partial ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #43035   +/-   ##
=========================================
  Coverage     77.32%   77.32%           
  Complexity    58536    58536           
=========================================
  Files          3460     3460           
  Lines        220048   219982   -66     
  Branches      28902    28872   -30     
=========================================
- Hits         170152   170107   -45     
- Misses        40484    40493    +9     
+ Partials       9412     9382   -30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shadow-Devil Shadow-Devil marked this pull request as ready for review July 3, 2024 18:27
@Shadow-Devil Shadow-Devil changed the title Fix constant expressions [Refactoring] Fix constant expressions Jul 3, 2024
@@ -263,8 +263,7 @@ public static boolean isJSONObject(Object json) {

MapValueImpl<BString, Object> map = new MapValueImpl<>(mapType);
Type mapConstraint = TypeUtils.getImpliedType(mapType.getConstrainedType());
if (mapConstraint == null || mapConstraint.getTag() == TypeTags.ANY_TAG ||
mapConstraint.getTag() == TypeTags.JSON_TAG) {
if (mapConstraint.getTag() == TypeTags.ANY_TAG || mapConstraint.getTag() == TypeTags.JSON_TAG) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in here do we handle mapConstraint == null

Copy link
Contributor Author

@Shadow-Devil Shadow-Devil Jul 4, 2024

Choose a reason for hiding this comment

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

TypeUtils.getImpliedType was inferred to always return non null values by IntelliJ.

image

See also the definition of TypeUtils.getImpliedType:

public static Type getImpliedType(Type type) {
Type impliedType = type.getCachedImpliedType();
if (impliedType != null) {
return impliedType;
}
type = getReferredType(type);
if (type.getTag() == TypeTags.INTERSECTION_TAG) {
impliedType = getImpliedType(((IntersectionType) type).getEffectiveType());
} else {
impliedType = type;
}
type.setCachedImpliedType(impliedType);
return impliedType;
}

It recursively calls itself until it finds a non null value or returns whatever getReferredType returns, but this has to be not null, since we access type.getTag().

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jul 30, 2024
@Shadow-Devil
Copy link
Contributor Author

Remove stale status

@github-actions github-actions bot removed the Stale label Jul 31, 2024
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added Stale and removed Stale labels Aug 23, 2024
Copy link

github-actions bot commented Sep 8, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Sep 8, 2024
@gimantha gimantha removed the Stale label Sep 9, 2024
@Shadow-Devil Shadow-Devil force-pushed the constant-expressions branch 2 times, most recently from f481184 to e37357d Compare September 12, 2024 18:43
@Shadow-Devil Shadow-Devil marked this pull request as draft September 16, 2024 19:45
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.

[Question]: Service and Object have the same TypeTag
5 participants