Skip to content

Comments

Add front end support for type test expressions#147

Merged
warunalakshitha merged 2 commits intoballerina-platform:mainfrom
heshanpadmasiri:feat/type-test-exp
Feb 24, 2026
Merged

Add front end support for type test expressions#147
warunalakshitha merged 2 commits intoballerina-platform:mainfrom
heshanpadmasiri:feat/type-test-exp

Conversation

@heshanpadmasiri
Copy link
Member

@heshanpadmasiri heshanpadmasiri commented Feb 17, 2026

Purpose

Resolves #145

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter �N/A� plus brief explanation of why there�s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type �Sent� when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type �N/A� and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

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

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • New Features

    • Added runtime type-test expressions (is and negated !is) with compiler, resolver, IR and pretty-printer support enabling type checks and narrowing.
  • Documentation

    • Expanded subset reference documenting type-test semantics and related language restrictions.
  • Examples / Tests

    • Added example programs demonstrating type tests; updated test corpus and skip-list entries accordingly.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds end-to-end support for type-test expressions: new AST node BLangTypeTestExpr and model.TypeTestExpressionNode, node builder, pretty‑printer and walker updates, semantic/type-resolver handling, desugaring, BIR TypeTest instruction and generation, example corpus files, and docs.

Changes

Cohort / File(s) Summary
AST
ast/expressions.go, ast/node_builder.go, ast/pretty_printer.go, ast/walk.go
Add BLangTypeTestExpr struct, interface conformance and accessors; implement TransformTypeTestExpression; add pretty-printer routing and printTypeTestExpr; include node in AST walker.
Model
model/tree.go
Add exported TypeTestExpressionNode interface with GetExpression() and GetType() accessors.
Semantic & Type Resolution
semantics/semantic_analyzer.go, semantics/type_resolver.go
Integrate BLangTypeTestExpr into semantic analysis; add resolveTypeTestExpr to resolve inner expression and tested TypeData and compute resulting boolean semtype (considering subtype/overlap/disjoint and negation).
Desugar
desugar/expression.go
Desugarer: handle BLangTypeTestExpr, preserve/init statements from inner expression.
BIR
bir/non_terminator.go, bir/bir_gen.go, bir/pretty_print.go
Introduce TypeTest BIR instruction (RhsOp, Type, IsNegation) with assign semantics; generate TypeTest in BIR generation; add pretty-printer for the instruction.
Corpus / Tests
corpus/bal/subset4/04-typetest/1-v.bal, corpus/bal/subset4/04-typetest/2-v.bal, corpus/parser/subset4/04-typetest/*, corpus/integration_test.go
Add example programs demonstrating is / !is, add parser LFS pointer files, and mark these tests as skipped in integration tests.
Docs
doc/subset4.md
Extend subset4 documentation with sections describing supported expressions (including type-test) and related restrictions.

Sequence Diagram

sequenceDiagram
    participant Parser
    participant SemanticAnalyzer
    participant TypeResolver
    participant Desugarer
    participant BIRGenerator
    participant Runtime

    Parser->>SemanticAnalyzer: emit BLangTypeTestExpr(Expr, Type, isNegation)
    SemanticAnalyzer->>TypeResolver: resolve type-test expression
    TypeResolver->>TypeResolver: resolve inner expr type and tested TypeData
    TypeResolver->>SemanticAnalyzer: return computed semtype (boolean / const)
    SemanticAnalyzer->>Desugarer: pass resolved BLangTypeTestExpr
    Desugarer->>BIRGenerator: produce desugared expression + init stmts
    BIRGenerator->>BIRGenerator: emit TypeTest instruction (LhsOp, RhsOp, Type, IsNegation)
    BIRGenerator->>Runtime: runtime representation
    Runtime->>Runtime: evaluate type test -> boolean (apply negation if set)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Suggested reviewers

  • warunalakshitha
  • gimantha

Poem

🐰
I hopped through nodes both small and grand,
Found "is" and "!is" across the land.
From parse to BIR I bounded light —
A testing hop in code tonight! 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only provides the issue reference (Resolves #145) but leaves all required template sections unfilled with placeholder text, providing minimal context about goals, approach, user stories, and implementation details. Complete the required template sections including Goals, Approach, User stories, Release note, and at least Documentation and Automation tests sections with specific details about the feature implementation.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding front-end support for type test expressions, which aligns with all modifications across AST, BIR, semantic analysis, and desugaring layers.
Linked Issues check ✅ Passed The changes comprehensively implement type test expression support across all required layers: AST nodes, BIR instructions, semantic analysis, type resolution, and desugaring, successfully addressing issue #145's objective to add front-end support for type test expressions.
Out of Scope Changes check ✅ Passed All changes are within scope and directly support type test expression feature implementation: AST/BIR structures, semantic analysis, type checking, pretty printing, and test corpus files demonstrating the feature.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
corpus/integration_test.go (1)

58-62: Make the skip intent explicit so it’s easy to revisit.

These new type-test cases are now excluded from the integration suite, which hides coverage for the new feature. Consider extracting the list into a helper with a descriptive name (and tracking the temporary nature in an issue) so it’s clear this is not permanent.

♻️ Example refactor to make the skip intent explicit
-	skipTestsMap = makeSkipTestsMap([]string{
-		"subset4/04-typetest/1-v.bal",
-		"subset4/04-typetest/2-v.bal",
-	})
+	skipTestsMap = makeSkipTestsMap(skipTestsWithRuntimePanics())
+
+func skipTestsWithRuntimePanics() []string {
+	return []string{
+		"subset4/04-typetest/1-v.bal",
+		"subset4/04-typetest/2-v.bal",
+	}
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@corpus/integration_test.go` around lines 58 - 62, Extract the two type-test
file paths into a clearly named helper function (e.g., skippedTypeTestFiles or
temporarilySkippedTypeTests) and replace the inline slice passed to
makeSkipTestsMap with a call to that helper; add a TODO comment in the helper
noting this is temporary and include an issue tracker ID or placeholder to
revisit/remove, so the skip intent is explicit when inspecting skipTestsMap and
makeSkipTestsMap.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@doc/subset4.md`:
- Line 66: Fix the typo in the documentation sentence "Only fallowing libraries
with given methods are supported" by replacing "fallowing" with "following" so
the line reads "Only following libraries with given methods are supported";
update the sentence in doc/subset4.md (the markdown text) to apply this
correction.
- Line 48: Update the typo in the markdown link text by changing "expressoin" to
"expression" in the link label "[Type test expressoin]" so it reads "[Type test
expression]" while leaving the URL
(https://ballerina.io/spec/lang/master/#section_6.28) unchanged.

---

Nitpick comments:
In `@corpus/integration_test.go`:
- Around line 58-62: Extract the two type-test file paths into a clearly named
helper function (e.g., skippedTypeTestFiles or temporarilySkippedTypeTests) and
replace the inline slice passed to makeSkipTestsMap with a call to that helper;
add a TODO comment in the helper noting this is temporary and include an issue
tracker ID or placeholder to revisit/remove, so the skip intent is explicit when
inspecting skipTestsMap and makeSkipTestsMap.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@doc/subset4.md`:
- Line 3: Change the heading text "Module level declarations" to use a hyphen
for consistency: update the heading string in doc/subset4.md from "Module level
declarations" to "Module-level declarations" (locate the heading line containing
that exact text).

In `@semantics/semantic_analyzer.go`:
- Around line 514-517: The BLangTypeTestExpr case is missing recursion into its
inner expression, so add an explicit call to analyzeExpression for expr.Expr
before calling validateResolvedType; locate the BLangTypeTestExpr case in the
semantic analyzer and insert analyzeExpression(a, expr.Expr, nil) (or the
appropriate expectedType if the branch requires it) immediately prior to the
call to validateResolvedType(a, expr, expectedType) so nested semantic errors
inside expr.Expr are analyzed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
bir/non_terminator.go (1)

194-201: Consider adding a NewTypeTest constructor for consistency with NewMove.

The GetLhsOperand and GetKind implementations correctly follow the established pattern. However, NewMove (the only similar assign instruction constructor) explicitly marks the destination operand as initialized. The current TypeTest instantiation in bir_gen.go (line 549) uses direct field assignment without this safeguard.

Adding a NewTypeTest constructor would align with the constructor pattern and ensure proper initialization of the destination operand, consistent with how variable assignments are handled elsewhere.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bir/non_terminator.go` around lines 194 - 201, Add a NewTypeTest constructor
that mirrors NewMove by creating and returning a *TypeTest while explicitly
marking the destination operand as initialized (e.g., set DestOp.Init = true or
the equivalent field on the destination operand). Replace direct struct literal
instantiations of TypeTest (the spots that currently assign fields directly) to
call NewTypeTest instead. Keep existing methods GetLhsOperand and GetKind
unchanged; ensure the constructor initializes all required fields (LhsOp,
DestOp, any type/test info) and follows the same initialization semantics used
by NewMove.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@doc/subset4.md`:
- Line 3: Update the heading "Module level declarations" in doc/subset4.md to
use a hyphen for consistency by changing it to "Module-level declarations";
locate the heading text within the file and replace the unhyphenated form with
the hyphenated form.

---

Nitpick comments:
In `@bir/non_terminator.go`:
- Around line 194-201: Add a NewTypeTest constructor that mirrors NewMove by
creating and returning a *TypeTest while explicitly marking the destination
operand as initialized (e.g., set DestOp.Init = true or the equivalent field on
the destination operand). Replace direct struct literal instantiations of
TypeTest (the spots that currently assign fields directly) to call NewTypeTest
instead. Keep existing methods GetLhsOperand and GetKind unchanged; ensure the
constructor initializes all required fields (LhsOp, DestOp, any type/test info)
and follows the same initialization semantics used by NewMove.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 75.28090% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 29.28%. Comparing base (fa7683c) to head (3170482).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
ast/expressions.go 20.00% 8 Missing ⚠️
semantics/type_resolver.go 66.66% 2 Missing and 3 partials ⚠️
bir/non_terminator.go 0.00% 4 Missing ⚠️
ast/pretty_printer.go 78.57% 1 Missing and 2 partials ⚠️
bir/pretty_print.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
+ Coverage   29.09%   29.28%   +0.19%     
==========================================
  Files         254      254              
  Lines       54231    54319      +88     
==========================================
+ Hits        15778    15908     +130     
+ Misses      37479    37427      -52     
- Partials      974      984      +10     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@heshanpadmasiri heshanpadmasiri added this to the M4 milestone Feb 20, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@doc/subset4.md`:
- Around line 82-110: Remove the duplicated top-level "Supported language
features (subset 4)" section and merge the two conflicting lists into one
authoritative section: keep the "Module level declarations" and "Statements"
subsections under a single heading, resolve contradictions by standardizing on
the spec terms (e.g., use "Shift expression" / "shift-expr" consistently),
ensure import support is stated once (use the accurate status for Import
declarations), and eliminate the duplicate heading to fix the lint; update or
combine entries for conflicting items like "Shift expression" vs "shift-expr"
and import differences so the final section is consistent and non-redundant.

@heshanpadmasiri heshanpadmasiri force-pushed the feat/type-test-exp branch 3 times, most recently from 16810e6 to 06d0864 Compare February 23, 2026 07:40
Copy link
Contributor

@warunalakshitha warunalakshitha left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Waruna Lakshitha <warunalakshitha@users.noreply.github.com>
@warunalakshitha warunalakshitha merged commit 032a2a9 into ballerina-platform:main Feb 24, 2026
5 of 6 checks passed
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.

Add front end support for type test expressions

2 participants