# Compiler flag to show all errors

**URL:** <https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073>\
**Category:** Help & Support\
**Created:** [November 20, 2021, 6:24am UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073 "2021-11-20T06:24:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![u89012](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/u89012/32/1021_2.png) [@u89012](https://forum.crystal-lang.org/u/u89012)\
**Post date:** [November 20, 2021, 6:24am UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/1 "2021-11-20T06:24:40Z")

</div>

Can we please have a compiler flag to show all errors (I’m not referring to --error-trace) in a compact one line format each, along with obviously the total error count? I’ve a really large experimental codebase and I’m really tired of fixing one error at a time and I’m sure others will find it handy too! Please? Please?!

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [November 20, 2021, 11:27am UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/2 "2021-11-20T11:27:02Z")

</div>

This is not as simple as adding a flag to enable multi error output. When the compiler encounters an error, it immediately stops. Because the program has already been proven to be invalid, there is not a known state from which to continue working. The compiler looks at the entire program as a whole, so there are no individual sub-units that could be considered separately.

However, we have recently iterated on some ideas to still allow the compiler to continue in a somewhat meaningful way by typing every broken piece as `NoReturn` and continue from that. This might work and help to identify lots of errors in the codebase. But so far there’s not even a PoC implementation of that, as a far as I know.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [November 20, 2021, 11:56am UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/3 "2021-11-20T11:56:39Z")

</div>

There’s also a new language in development called Roc where you have a way to make compile errors be runtime errors. Well, you get to see the whole list of compile errors, but it still produces a “valid” program that, when facing those code paths, will give a runtime error with that compile time error, if that makes sense.

I think it would be great to implement this for our compiler, but it’s a pretty big and challenging task.

To give some ideas for whoever decides to implement this…

## Undefined constant

If you use an undefined constant, report a compile error but define the constant as a module and go on. For example:

```crystal
puts FOO

```

Will give at compile time:

“Undefined constant FOO”

but will produce a program that, when you run it, outputs “FOO” (since FOO is defined as a module)

## No method, or no overload matches

If you call a method that doesn’t exist, the compiler records the error and defines a method with the given types that raises on runtime with that same error:

```crystal
class Foo
end

foo = Foo.new
foo.hello(1)

```

At compile-time you get:

“Undefined method `hello` for `Foo`”

but the compiler defines this method:

```crystal
class Foo
  def hello(value : Int32)
    raise "Undefined method `hello` for `Foo`"
  end
end

```

and goes on.

## Tricky part

The tricky part is when you assign a type to a variable that can’t hold that type:

```crystal
class Foo
  property x = 0
end

foo = Foo.new
foo.x = "Hello"

```

I don’t know what can be done there… maybe the call should be replaced with something else that raises at runtime, or maybe these can’t produce a working binary.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [November 20, 2021, 7:13pm UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/4 "2021-11-20T19:13:04Z")

</div>

I don’t see the tricky thing in the tricky part. Isn’t `Foo#x=(String)` just an undefined method, like `Foo#hello(Int32)` in the example before?

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [November 20, 2021, 7:38pm UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/5 "2021-11-20T19:38:08Z")

</div>

Ah, yes. I guess it’s tricky if it’s an assignment directly to an instance var.

---

<div class="post-metadata">

**Author:** ![u89012](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/u89012/32/1021_2.png) [@u89012](https://forum.crystal-lang.org/u/u89012)\
**Post date:** [November 21, 2021, 4:47am UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/6 "2021-11-21T04:47:52Z")

</div>

Thank you both! I suspected it wasn’t going to be easy and that Crystal probably stopped right after the first error. The problem I see with this approach is when working with a large codebase the actual effort involved to get to a working program stage cannot be estimated. When I sit down to code I normally find myself coding to get as many ideas out of my head as possible. Hopefully most of them work the way I want it to but given the slow compilation in Crystal I normally don’t wish to run the compiler after every change to save time. I really wish there was a way to add this to Crystal by considering sub-units perhaps at the class or file level?

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [November 21, 2021, 9:25am UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/7 "2021-11-21T09:25:32Z")

</div>

There are no sub-units. The language doesn’t work like that. I understand what you want, and it’s what everyone wants and wanted for a long time, but there’s no actual way to do it.

---

<div class="post-metadata">

**Author:** ![jgaskins](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jgaskins/32/2449_2.png) [@jgaskins](https://forum.crystal-lang.org/u/jgaskins)\
**Post date:** [November 21, 2021, 11:04pm UTC](https://forum.crystal-lang.org/t/compiler-flag-to-show-all-errors/4073/8 "2021-11-21T23:04:52Z")

</div>

> [@u89012](#):
>
> I really wish there was a way to add this to Crystal by considering sub-units perhaps at the class or file level?

I normally write tests at this level specifically because Crystal doesn’t support this. One of the first things I do in any new Crystal project is remove the `require "../src/#{project_name}"` line from `spec/spec_helper.cr` so it doesn’t try to compile the whole project just so I can test one method in one class.

Keeping tests small and focused like that has helped me because I have a similar “brain-dump then organize” style of writing code. Maybe it could help you?
