Swan Lake Alpha4

Overview of Ballerina Swan Lake Alpha4

This is the fourth Alpha release in a series of planned Alpha and Beta releases leading up to the Ballerina Swan Lake GA release.

It introduces the new language features planned for the Swan Lake GA release and includes improvements and bug fixes done to the compiler, runtime, standard library, and developer tooling after the Swan Lake Alpha3 release.

Updating Ballerina

If you are already using Ballerina, you can use the update tool to directly update to Ballerina Swan Lake Alpha4 as follows.

To do this, first, execute the command below to get the update tool updated to its latest version.

bal update

If you are using an update tool version below 0.8.14, execute the ballerina update command to update it. Next, execute the command below to update to Swan Lake Alpha4.

bal dist pull slalpha4

Installing Ballerina

If you have not installed Ballerina, then download the installers to install.

Language updates

New features

Relational expressions with all ordered types

Relational expressions (<, >, <=, and >=) are supported with all ordered types. The static type of both operands must belong to the same ordered type.

Inferring the argument of a dependently-typed function from the contextually-expected type

When the default value of a typedesc parameter of a dependently-typed function is <> and an argument is not provided for the parameter when calling the function, the argument will be inferred from the contextually-expected type of the function call.


Improvements to dependently-typed lang library functions to infer the argument from the contextually-expected type
  • The lang:value:ensureType lang library function is now dependently-typed.

  • The typedesc argument of the lang.value:cloneWithType, lang.value:fromJsonWithType, lang.value:fromJsonStringWithType, and lang.value:ensureType dependently-typed lang library functions will be inferred from the contextually-expected type if it is not passed as an argument.

Improvements to the return type of lang.value:cloneReadOnly

Changed the return type of the lang.value:cloneReadOnly lang library function from the type of the value (T) to the intersection of the type and readonly (T & readonly).

Changes to the return types of lang.value:fromJsonFloatString and lang.value:fromJsonDecimalString

Changed the return types of the lang.value:fromJsonFloatString and lang.value:fromJsonDecimalString lang library functions from json to lang.value:JsonFloat and lang.value:JsonDecimal respectively.

Breaking changes

  • A compilation error occurs if the inferred type of an unused variable that is declared with var includes a subtype of the error type.
  • Removed the error<*> syntax.
  • Removed support for relational expressions with numeric values when the static types of the operands belong to different ordered types.
  • The lang.array:indexOf and lang.array:lastIndexOf lang library functions cannot be used with values that do not belong to anydata.
  • An object used as the iterable value in a foreach statement, from clause, or join clause must be a subtype of object:Iterable.
  • The RawTemplate type is distinct now.
  • The filler value of the decimal type is now +0d.
  • Changed the completion type C in stream<T, C> from error|never to error?. stream<T> is equivalent to stream<T, ()>. stream<T> and stream<T, error> are assignable to stream<T, error?>.
  • Annotations with the service attach point cannot be used with service classes.
  • Checking keywords (check and checkpanic) are allowed in a statement only if the statement is a call statement (i.e., when the expression is a function or method call).
  • Lowered the precedence of the trap expression.

Bug fixes

To view bug fixes, see the GitHub milestone for Swan Lake Alpha4.

Runtime updates

New features

Providing values for configurable variables via command-line arguments

Configurable values can be provided with the built-in command-line option -C.

Key syntax:

Command-line arguments are supported for configurable variables with boolean, int, float, decimal, string, and xml types.

Example usages:

  • If the configurable variable is defined in the default module or if a single Ballerina file is being used:

  • If the configurable variable is defined in a different module of the same organization:

  • If the configurable variable is defined in a module of a different organization.

Locating multiple TOML files

Configurable values can be provided in multiple TOML files using the BAL_CONFIG_FILES environment variable.

The file locations can be specified in the environment variable using an OS-specific separator. The precedence order will be determined by the order in which the files are specified in the environment variable. If such an environment variable is not specified, the file located in the current directory with the file name Config.toml will be used.

Providing TOML content via environment variables

The configurable values can be provided using the BAL_CONFIG_DATA environment variable in which the content is expected to be in the TOML (v0.4) format.

Bug fixes

To view bug fixes, see the GitHub milestone for Swan Lake Alpha4.

Standard library updates


time package

Introduced the following APIs to support email-typed string conversions:

  • Converts a given UTC to an email string.
  • Converts a given time:Civil to an email string.
  • Converts a given email string to time:Civil.
io package
  • Improved the print APIs to support string templates.
  • Changed streaming APIs to be completed from nil return.
mysql package
  • Changed the previous SSLConfig Record to SecureSocket Record.
  • Changed the SSLMode value from SSL_VERIFY_CERT to SSL_VERIFY_CA.
xmldata package

Updated the API to convert a JSON to an XML to be supported by the nil return value.

java.arrays package

Renamed the java.arrays package’s org and package names as ballerina and jballerina.java.arrays.

websub package

Added pre-built constants for WebSub common-responses.

kafka package
  • Updated the SecureSocket record.

  • Updated the init methods of the kafka:Producer, kafka:Consumer, and kafka:Listener classes.

nats package

Updated the init methods of the client and listener.

stan package

Updated the init methods of the client and listener.

rabbitmq package

Updated the init methods of the client and listener.

Security updates

Removed encrypted passwords and hashed passwords support for Basic Auth file user store authentication.

Bug fixes

To view bug fixes, see the GitHub milestone for Swan Lake Alpha4.

Developer tools updates

Bug fixes

To view bug fixes, see the GitHub milestone for Swan Lake Alpha4 of the repositories below.

Language server

To view bug fixes, see the GitHub milestone for Swan Lake Alpha4.

Observability updates

  • Introduced the open-telemetry standard for Ballerina tracing instead of open-tracing
  • Updated the Jaeger extension to support open-telemetry