Crystal 1.7.0 is released!
We are starting the year with a new release with several bugfixes and improvements. Below we list the most important or interesting changes, without mentioning several bugfixes and smaller enhancements. For more details, visit the changelog. Breaking changes are marked with ⚠️.
Pre-built packages are available on GitHub Releases and our official distribution channels. See crystal-lang.org/install for installation instructions.
Stats
In this release we included 152 changes since the 1.6.2 release by 38 contributors. We thank all the effort put into improving the language! ❤️
Below we list the most remarkable changes in the language, compiler and stdlib.
Interpreter REPL
The REPL interface of the interpreter has received a major usability improvement. The command prompt now supports multiline input, command history, and several key bindings.
This great feature set is provided by the shard REPLy (#12738).
For technical reasons, the interpreter currently only ships by default in brew
. For other platforms you need to compile it from the sources with interpreter=1
in the make
options.
Regex
with PCRE2
Crystal relies on libpcre
as engine for executing regular expressions in Regex
.
In 1.7.0 we’re adding support for its successor, libpcre2
, but for now it’s opt-in with the compiler flag -Duse_pcre2
.
There are no major differences in usage and PCRE2 is mostly backwards compatible. So we don’t expect many issues. But we still encourage testing out the new engine to see if something breaks.
PCRE2 is going to be enabled implicitly in one of the next releases, likely becoming the default engine. PCRE will continue to serve as a fallback when the newer library is not available. See #12790 for the tracking issue.
The regex engine is also used in the compiler for validating regex literals. Updating the compiler to PCRE2 might cause some friction due to minor syntactical differences. Using different regex engines in the compiler and the compiled program may lead to the compiler rejecting a regex literal for syntax errors, even if it’s valid for the runtime engine. Read more about the implications on the language syntax in #12857.
Misc
Language
- Lib functions are now visible in top-level macros (#12848).
- Added
ArrayLiteral#-(other)
andTupleLiteral#-(other)
(#12646). annotation
supports the@[Deprecated]
annotation now (#12557).- Removed oct/bin floating point literals. This number syntax had been broken and isn’t very useful anyway… (#12687).
Compiler
⚠️ Obsolete FreeBSD 11 compatibility was dropped (#12612).
stdlib
⚠️ File.real_path
was renamed to File.realpath
. This spelling just makes more sense as it’s used everywhere else. The old version is deprecated, but keeps working until the next major release (#12552).
⚠️ Error handling for libXML2
does no longer leak errors outside the current context. XML.errors
has been deprecated, but should continue to work. We highly recommend to access errors directly in the respective context via XML::Reader#errors
and XML::Node#errors
(#12663, #12795).
File#flock_shared
and File#flock_exclusive
are now fiber-aware and when they block, they’re no longer blocking the thread (#12861).
They’re now also supported on Windows (#12766).
BigDecimal#to_s
supports scientific notation (#10805).
BigDecimal.new(Float32::MAX) # => 3.4028235e+38
Further additions:
- Automatically cast from
Int
toFloat
forJSON::Any#as_f
andYAML::Any#as_f
(#12835). - Several missing
#index!
/#rindex!
methods onString
andIndexable
(#12730, #12759). - Methods to manipulate
SemanticVersion
(#12834). HTTP::Server::Response#redirect
(#12526).
Code quality
There were a couple of changes to improve code quality in the entire repository. Most of them are based on suggestions by the static code analyzer tool ameba. Nothing is automated yet, so we can’t ensure this for code additions. But that would one of the next steps.
A nice feature supported by many code highlighters is context-specific heredoc deliminators. We implemented that accross the code base in #12816.
html_string = <<-HTML
<p>This uses HTML code highlighting!</p>
HTML
Shards 0.17.2
This Crystal release comes with a new release of shards
: version 0.17.2.
It brings two small improvements:
- Better error message when creating a symlink fails on Windows (with a recommendation to enable developer mode).
- A program executed with
shards run
now inherits stdin (ascrystal run
does).