Skip to content

Raise compile errors on relevant type node#1149

Merged
jwoertink merged 1 commit into
luckyframework:mainfrom
akadusei:typenode-raise
Apr 29, 2026
Merged

Raise compile errors on relevant type node#1149
jwoertink merged 1 commit into
luckyframework:mainfrom
akadusei:typenode-raise

Conversation

@akadusei
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, I've never really understood what this does 🤔 Does it just make the stack trace contain a better set of line numbers or something? Should all compile-time exceptions always raised on the type node when the error is based around a specific node?

@akadusei
Copy link
Copy Markdown
Contributor Author

Before:

In src/avram/callbacks/after_commit_callback.cr:92:3

 92 | after_commit { }
      ^-----------
Error: The 'after_commit' callback requires exactly 1 block arg to be passed.

After:

In src/avram/callbacks/after_commit_callback.cr:92:16

 92 | after_commit { }
                   ^
Error: The 'after_commit' callback requires exactly 1 block arg to be passed.

Basically points to the exact node causing the error.

@akadusei
Copy link
Copy Markdown
Contributor Author

Before:

In src/avram/define_attribute.cr:91:3

 91 | attribute aaa : String?
      ^--------
Error: `attribute` in Avram::DefineAttribute must not be called with a type union or nilable type but was called with String | ::Nil

After:

In src/avram/define_attribute.cr:93:19

 93 | attribute aaa : String?
                      ^
Error: `attribute` in Avram::DefineAttribute must not be called with a type union or nilable type but was called with String | ::Nil

The pointer points to the String? rather than the whole method/macro. Helpful if there's a lot of code in there

@jwoertink
Copy link
Copy Markdown
Member

ooohh! Ok, that's awesome. I never realized that. Thanks for explaining.

@jwoertink jwoertink merged commit a620fae into luckyframework:main Apr 29, 2026
15 checks passed
@akadusei akadusei deleted the typenode-raise branch May 9, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants