Hi. I'm completely new to Roc so apologies is this is a stupid question!
I'm working through some of the exercises on Exercism and I'm getting this warning on one of them:
── ● unreachable code ─ ../../../../.cache/roc/packages/4W8SHzvwet9hH9qZewJ1J1CVQoH7YKA6zyijWFTB3y1w/InternalGrapheme.roc:245:2
This code will never run, because the code before it always ends with a return, crash, or break, or loops forever.
Err(NoMore)
^^^^^^^^^^^
Remove this code, or change the code before it so that it can finish.
The code is:
import unicode.Grapheme
MicroBlog :: {}.{
truncate : Str -> Try(Str, _)
truncate = |input| {
grapheme_list = Grapheme.split(input).take_first(5)
Ok(Str.join_with(grapheme_list, ""))
}
}
Am I doing something wrong, or is it a bug in InternalGrapheme.roc?
What roc build are you using? Can you post a snippet from the InternalGrapheme.roc (near line 245) for more context?
Roc compiler version nightly-2026-10-21-5349569
The test code (in a separate file) is using:
app [] {
unicode: "https://github.com/roc-lang/unicode/releases/download/4.2.0/4W8SHzvwet9hH9qZewJ1J1CVQoH7YKA6zyijWFTB3y1w.tar.zst",
}
Looking at https://github.com/roc-lang/unicode/blob/main/package/InternalGrapheme.roc line 245 is the end of a function that starts:
next_range : RangeIterState -> Try((ByteRange, RangeIterState), [NoMore])
next_range = |state| {
if state.finished {
return Err(NoMore)
}
But I don't know if that's the version of the package that the test code is using...
I'm just posting the whole function for convenience:
next_range : RangeIterState -> Try((ByteRange, RangeIterState), [NoMore])
next_range = |state| {
if state.finished {
return Err(NoMore)
}
var $cursor = state.cursor
var $machine = state.machine
while Bool.True {
match InternalUtf8.next($cursor) {
Done => {
if $machine.started {
range = ByteRange.from_bounds($machine.cluster_start, $cursor.byte_offset) ?? ...
return Ok((
range,
{
cursor: $cursor,
machine: $machine,
finished: Bool.True,
},
))
} else {
return Err(NoMore)
}
}
One({ item, rest }) => {
transition = InternalGrapheme.push($machine, item.scalar, item.byte_start)
$cursor = rest
$machine = transition.machine
match transition.boundary {
NoBoundary => {}
Boundary({ start, end }) => {
range = ByteRange.from_bounds(start, end) ?? ...
return Ok((
range,
{
cursor: $cursor,
machine: $machine,
finished: Bool.False,
},
))
}
}
}
}
}
}
Ah, updating test file to use version 4.3.1 seems to fix the problem...
Interesting! The error message definitely seems bogus, because finished is clearly a bool, so the conditional up top that Roc was whining about doesn't always fire.
RangeIterState : {
cursor : InternalUtf8.Cursor,
machine : MachineState,
finished : Bool,
}
I was using roc locally, rather than the Exercism browser version. Perhaps the test worked fine using the older version of the unicode package with whatever version of the compiler Exercism are using.
Anyway, using the latest version seems to work correctly so I guess it's not really a problem. Thanks for looking at it.
When I encounter compiler errors/warnings in official packages, it's nearly always a version incompatibility that goes away after I update the compiler to the latest nightly and the package to the latest released version.
This issue has been reported here.
Last updated: Nov 04 2026 at 18:54 UTC