Skip to content

Conversation

@MaryamZi
Copy link
Member

@MaryamZi MaryamZi commented Apr 9, 2025

Purpose

$title.

Positive tests will go in the library module.

Fixes #43945

@MaryamZi MaryamZi closed this Apr 9, 2025
@MaryamZi MaryamZi reopened this Apr 9, 2025
@MaryamZi MaryamZi requested a review from KavinduZoysa as a code owner April 11, 2025 17:07
@MaryamZi MaryamZi force-pushed the natural-programming branch from c8fcb0b to 7726ada Compare April 12, 2025 02:20
@codecov
Copy link

codecov bot commented Apr 12, 2025

Codecov Report

Attention: Patch coverage is 65.36313% with 62 lines in your changes missing coverage. Please review.

Please upload report for BASE (natural-programming@c092499). Learn more about missing BASE report.
Report is 36 commits behind head on natural-programming.

Files with missing lines Patch % Lines
.../compiler/semantics/analyzer/DataflowAnalyzer.java 0.00% 10 Missing ⚠️
...piler/tree/expressions/BLangNaturalExpression.java 55.55% 8 Missing ⚠️
...llerinalang/compiler/desugar/ClosureGenerator.java 0.00% 5 Missing ⚠️
...rinalang/compiler/desugar/ConstantPropagation.java 0.00% 5 Missing ⚠️
...2/ballerinalang/compiler/desugar/QueryDesugar.java 0.00% 5 Missing ⚠️
...inalang/compiler/tree/SimpleBLangNodeAnalyzer.java 0.00% 5 Missing ⚠️
...ava/io/ballerina/compiler/api/impl/NodeFinder.java 0.00% 4 Missing ⚠️
...o/ballerina/compiler/api/impl/ReferenceFinder.java 0.00% 4 Missing ⚠️
...a/io/ballerina/compiler/api/impl/SymbolFinder.java 0.00% 4 Missing ⚠️
...lang/compiler/semantics/analyzer/CodeAnalyzer.java 0.00% 4 Missing ⚠️
... and 5 more
Additional details and impacted files
@@                  Coverage Diff                   @@
##             natural-programming   #43993   +/-   ##
======================================================
  Coverage                       ?   74.99%           
  Complexity                     ?    57662           
======================================================
  Files                          ?     3546           
  Lines                          ?   223032           
  Branches                       ?    28868           
======================================================
  Hits                           ?   167264           
  Misses                         ?    46493           
  Partials                       ?     9275           

☔ 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.

String moduleName, DependencyResolutionType dependencyResolutionType) {
if (!currentModuleDesc.name().toString().equals(moduleName)) {
ModuleLoadRequest moduleLoadRequest = new ModuleLoadRequest(
PackageOrg.from(orgName), moduleName, scope, dependencyResolutionType);
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 Don't we need to consider about the language version
As an example np module can have different versions for U12 and U13

Copy link
Member Author

Choose a reason for hiding this comment

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

That's resolved by the project API? Which is why we shouldn't specify a version here?

*/
public class NaturalProgrammingImportAnalyzer extends NodeVisitor {

private boolean shouldImportNaturalProgrammingModule;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private boolean shouldImportNaturalProgrammingModule;
private boolean shouldImportNaturalProgrammingModule = false;

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in #44013.

EXPECTED_TYPE_FOR_NATURAL_EXPR_MUST_CONTAIN_ERROR("BCE4070", "expected.type.for.natural.expr.must.contain.error"),
EXPECTED_TYPE_FOR_NATURAL_EXPR_MUST_CONTAIN_A_UNION_OF_NON_ERROR_AND_ERROR(
"BCE4071", "expected.type.for.natural.expr.must.contain.a.union.of.non.error.and.error"),
EXPECTED_TYPE_FOR_NATURAL_EXPR_MUST_BE_A_SUBTYPE_OF_ANYDATA_OR_ERROR(
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont we need to avoid the regexp in here

Copy link
Member Author

Choose a reason for hiding this comment

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

Why though?


@Override
public String toString() {
return "BLangNaturalExpression: strings " + strings + ", insertions " + insertions;
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont we need to construct the original expression in here, Same thing done by the SQL queries

Copy link
Member Author

Choose a reason for hiding this comment

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

I've kept this consistent with other templates in the language.

return externalFunctionBodyNode.annotations().stream()
.anyMatch(annotation ->
annotation.annotReference() instanceof SimpleNameReferenceNode annotReference &&
CODE_ANNOTATION.equals(annotReference.name().text()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since code is a common name, shall we check the prompt field also?

Copy link
Member Author

Choose a reason for hiding this comment

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

It'll have the module prefix then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like we don't give a redeclared symbol error for code in the current module. Will fix this for m2.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is when there is a code annotation in the current module.

@MaryamZi
Copy link
Member Author

Adding more tests, WIP.

@MaryamZi
Copy link
Member Author

Merging to trigger a timestamped build - will send a separate PR with tests/addressing other suggestions if any.

@MaryamZi MaryamZi merged commit 6c68428 into ballerina-platform:natural-programming Apr 16, 2025
19 checks passed
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org).
*
* WSO2 Inc. licenses this file to you under the Apache License,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be LLC

import java.util.List;

/**
* Represents a natural expression.
Copy link
Contributor

Choose a reason for hiding this comment

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

Represents a natural expression in AST

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, self-explanatory, given where it is and the class name.

boolean constNaturalExpr = naturalExpression.constExpr;

if (!constNaturalExpr && !types.isSubtype(symTable.errorType, expTypeSemType)) {
dlog.error(naturalExpression.pos, DiagnosticErrorCode.EXPECTED_TYPE_FOR_NATURAL_EXPR_MUST_CONTAIN_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

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

Cant we use the regular incompatible types error here. The main issue is in the error message we say the expected type is incorrect but the position we use for the error msg is the expression pos

Copy link
Member Author

Choose a reason for hiding this comment

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

That's why I introduced a specific error message. This is a dependently-typed expression, so saying expected anydata found T for the expected type doesn't really work.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is, if we consider an assignment, we are saying that the LHS type is incorrect while giving the error on the RHS.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a commn concern with dependently-typed expressions. I think the current error explains the issue better to the user compared to giving an error to the expected type. The error needs to work with all kinds of places in which a natural expression is used.

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.

3 participants