V0.1.6 RELEASE NOTES

Braden Steffaniak - Aug 19, 2022

DOWNLOAD BETA v0.1.6

NOTABLE CHANGES

tl;dr:

Statements as expressions [Issue #199] permalinkpermalink

Control structure statements can now be used as expressions. The affected statements types include:

If statementspermalink
Returnspermalink

Previously returns would need to be written as such:

if (file.isDirectory || file.isSymbolicLink) {
  return location + "/flat.json"
} else if (file.isFile) {
  return file.location
} else {
  throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}

Now they can be written as such:

return if (file.isDirectory || file.isSymbolicLink) {
  location + "/flat.json"
} else if (file.isFile) {
  file.location
} else {
  throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}
Assignmentspermalink

Previously variable assignments would need to be written as such:

var String result

if (file.isDirectory || file.isSymbolicLink) {
  result = location + "/flat.json"
} else if (file.isFile) {
  result = file.location
} else {
  throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}

Now they can be written as such:

let result = if (file.isDirectory || file.isSymbolicLink) {
  location + "/flat.json"
} else if (file.isFile) {
  file.location
} else {
  throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}
Match statementspermalink
Returnspermalink

Previously returns would need to be written as such:

match (package) {
  "main" => return mainSource
  "test" => return testSource
  default => throw InvalidCommandException("Invalid installation package '#package'")
}

Now they can be written as such:

return match (package) {
  "main" => mainSource
  "test" => testSource
  default => throw InvalidCommandException("Invalid installation package '#package'")
}
Assignmentspermalink

Previously variable assignments would need to be written as such:

var Package result

match (package) {
  "main" => result = mainSource
  "test" => result = testSource
  default => throw InvalidCommandException("Invalid installation package '#package'")
}

Now they can be written as such:

let result = match (package) {
  "main" => mainSource
  "test" => testSource
  default => throw InvalidCommandException("Invalid installation package '#package'")
}

Remove "new" keyword from constructor calls [Issue #408] permalink

The new keyword is no longer necessary (or allowed) when calling a constructor. It is redundant and adds extra characters, and does not add any extra clarity as long as basic naming conventions are followed. The change does not apply to array initializations (array initializations still require the new keyword).

Example:permalink

Previously constructors that were called like this:

CliArg("--link", String[], minCount: 0, maxCount: 1)

can (and must) now be:

CliArg("--link", Array<String>(), minCount: 0, maxCount: 1)

Add target runtimes [Issue #410] permalink

You can now use the [TargetRuntime] annotation to target specific runtimes for runtime specific code. For example, [TargetRuntime browser] can be used to only compile browser specific code. An example use case of this is if you want to handle logging differently depending on the runtime. In node you may want to use process.stdout instead of console.log for messages:

[TargetRuntime browser]
logMessage(String message) {
  external js {
    console.log(#{message.chars.data});
  }
}

[TargetRuntime not browser]
logMessage(String message) {
  external js {
    process.stdout.write(#{message.chars.data} + "\n");
  }
}

Handle primitive null assignmentspermalink

Variables of a primitive type are now handled as reference types when they are assigned as null.

Handle inline local declaration assignmentspermalink

The Flat compiler now adds metadata to local declarations and assignments so that the code generators can generate inline local declaration assignments.

General bug fixes [Issue #403]permalink

  • Fixed some method calls with unambiguous argument names failing as ambiguous.
  • Fixed null checks being added inside wrong scope for safe navigation operators in if statement condition.
  • Fix redundant returns from being generated to transpiled code.
POSTS DOCUMENTATION