Skip to content

[Bug] Fix incorrect error message for resource functions (#43815)#44552

Open
chamod-malindu wants to merge 1 commit intoballerina-platform:masterfrom
chamod-malindu:fix/issue-43815-resource-function-error
Open

[Bug] Fix incorrect error message for resource functions (#43815)#44552
chamod-malindu wants to merge 1 commit intoballerina-platform:masterfrom
chamod-malindu:fix/issue-43815-resource-function-error

Conversation

@chamod-malindu
Copy link
Copy Markdown

@chamod-malindu chamod-malindu commented Apr 12, 2026

Purpose

Fixes issue #43815 by replacing the internal AST enum string "resource_func" with the correct language keyword "resource function" in the BCE2095 compiler error message.

Previously, if a resource function was missing a return statement, the compiler logged:

this resource_func must return a result

It will now correctly log:

this resource function must return a result

Related Issues

Fixes #43815

Changes

  • ReachabilityAnalyzer.java: Added a condition when formatting the DiagnosticErrorCode.INVOKABLE_MUST_RETURN argument so that NodeKind.RESOURCE_FUNC translates to "resource function" rather than relying on the bare toLowerCase() enum string representation.

Testing

This relies on existing jballerina-unit-test suites for diagnostic message validation. Submitting so CI can verify standard reachability tests against the updated string.

Summary

This pull request fixes an incorrect compiler diagnostic message that was using an internal AST enum representation instead of the proper language keyword. The change improves the clarity and user-friendliness of error messages reported by the Ballerina compiler.

Changes

Modified file: ReachabilityAnalyzer.java

Updated the INVOKABLE_MUST_RETURN diagnostic message to display "resource function" instead of "resource_func" when a resource function is missing a return statement. The fix adds a specialized condition that checks if the function kind is NodeKind.RESOURCE_FUNC and maps it to the human-readable display string "resource function", while maintaining the existing behavior for other function types.

Impact: Users will now see the correct, language-appropriate error message: "this resource function must return a result" instead of the previous internal representation "this resource_func must return a result".

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 12, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad403bbf-9851-4bf4-acd4-a62775dbcb84

📥 Commits

Reviewing files that changed from the base of the PR and between f59068a and ba4d6bf.

📒 Files selected for processing (1)
  • compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java

📝 Walkthrough

Walkthrough

The ReachabilityAnalyzer diagnostic message for resource functions has been updated to display "resource function" instead of "resource_func" when reporting the INVOKABLE_MUST_RETURN error, improving message clarity for resource function nodes.

Changes

Cohort / File(s) Summary
Diagnostic Message Fix
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java
Updated the INVOKABLE_MUST_RETURN diagnostic to report "resource function" for resource function nodes instead of the lowercased kind "resource_func", making error messages more user-friendly.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A message once said "resource_func" with pride,
But now it reads "resource function" wide!
With three little lines, the bug took its flight,
Error messages clearer, everything's right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the bug fix by identifying it as correcting an incorrect error message for resource functions, directly matching the changeset.
Description check ✅ Passed The description covers the purpose and changes, but is missing test coverage details and the contributing guide checklist sections from the template.
Linked Issues check ✅ Passed The PR correctly addresses issue #43815 by replacing 'resource_func' with 'resource function' in the compiler error message as required.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to fixing the diagnostic message for resource functions; no unrelated modifications are present in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

[Bug]: Invalid error message: must be resource function instead of resource_func

2 participants