moonbit-docs icon indicating copy to clipboard operation
moonbit-docs copied to clipboard

"The error type of this function is never used" should be a warning rather than an Error

Open zxch3n opened this issue 2 months ago • 3 comments

Bug Report

Environment

OS

Operating System: macOS

MoonBit CLI Tools Version

moon 0.1.20250918 (e5fa392 2025-09-18) ~/.moon/bin/moon moonc v0.6.28+d96d14d39 (2025-09-18) ~/.moon/bin/moonc moonrun 0.1.20250918 (e5fa392 2025-09-18) ~/.moon/bin/moonrun moon-pilot 0.0.1-850379f (2025-09-19) ~/.moon/bin/moon-pilot


Steps to Reproduce

Create a function with a return type of 'Unit raise Error'

Expected Behavior

See a compiler warning not an error. Because users may want to use that error in the future.

Actual Behavior

Cannot compile successfully.

zxch3n avatar Sep 29 '25 08:09 zxch3n

This is actually intended behavior. By making unused error an error instead of a warning, users are enforced to think carefully whether a function may raise error, this helps avoid unnecessary error annotation and make code more robust. Do you have any use case where this behavior result in problems that cannot be fixed by simply removing the unnecessary error annotation?

Guest0x0 avatar Oct 09 '25 09:10 Guest0x0

Excessive compiler errors increase the cost of prototyping and experimentation. Suppose I have an unimplemented function A that, in its eventual full implementation, will throw a specific error. Today, however, the compiler forces me either to remove that error type or to hack around it with something like if (true) { raise Error }.

Allowing an incomplete implementation helps me first validate the main path. At the same time, keeping the intended error type lets downstream code prepare proper handling early and keeps both sides’ interfaces aligned—so we don’t have to retrofit the error type later and make every downstream caller change again.

zxch3n avatar Oct 11 '25 02:10 zxch3n

@zxch3n will fix it soon

bobzhang avatar Nov 05 '25 10:11 bobzhang