Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler: show warnings even if there are errors #9461

Merged

Conversation

asterite
Copy link
Member

Fixes #9460

Now warnings are shown even if there are errors.

I also cleaned up the code so that warnings are reported in the semantic phase, not the in the codegen phase.

Now this snippet:

abstract class Foo
  abstract def write : Int64
end
 
class Bar < Foo
  def write : Int64 # Error: method must return Int64 but it is returning Nil
    Baz.new.write
  end
end
 
class Baz < Foo
  def write # The error should be reported here!
    nil
  end
end
 
Bar.new.write

Gives this error:

In foo.cr:12:7

 12 | def write # The error should be reported here!
          ^----
Warning: this method overrides Foo#write() which has an explicit return type of Int64.

Please add an explicit return type (Int64 or a subtype of it) to this method as well.

The above warning will become an error in a future Crystal version.

A total of 1 warnings were found.
Showing last frame. Use --error-trace for full trace.

In foo.cr:6:15

 6 | def write : Int64 # Error: method must return Int64 but it is returning Nil
                 ^
Error: method must return Int64 but it is returning Nil

You can see that the warning tells you that the return type is wrong, which then connects to the error below.

If you want to fix this is another way, let me tell you that it's impossible. The idea is that abstract method errors must kick before the semantic phase, but right now they are warnings so that's impossible to do. The real solution is to make those warning be errors, but first #8766 and #8232 (which is not a bug to me, the user should define the exact method that's wanted, and later they can do a dispatch if they want) must be fixed.

@bcardiff bcardiff added this to the 0.35.1 milestone Jun 11, 2020
@bcardiff bcardiff merged commit 5c68a02 into crystal-lang:master Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading error for abstract method return type
2 participants