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

Fix issue #13063 #19165

Closed
wants to merge 5 commits into from
Closed

Fix issue #13063 #19165

wants to merge 5 commits into from

Conversation

treeform
Copy link
Contributor

No description provided.

@quantimnot
Copy link
Contributor

quantimnot commented Nov 20, 2021

@treeform
Here is what I've noticed after inspecting the code:

type Foo = object
template `?`(a: Foo, b: untyped): untyped = 123
type Bar = object
  x1: int
var b: Bar
echo b?x
  • The compiler thinks . is a call and no error is set, so it defaults to cannot be called.

Is is correct to treat

type Foo = object
template `.`(a: Foo, b: untyped): untyped = 123
type Bar = object
  x1: int
var b: Bar
echo b.x

differently than

type Foo = object
template `?`(a: Foo, b: untyped): untyped = 123
type Bar = object
  x1: int
var b: Bar
echo b?x

?

Are we deciding to treat it differently because it is overloading the already heavily used dot operator? What if the user tried to make a dot override, but they made a typo. Wouldn't the override error message be useful then?

Should both errors be output? Like:

tdotopserrors1.nim(16, 7) Error: undeclared field: 'x' for type tdotopserrors1.Bar [type declared in tdotopserrors1.nim(12, 6)]
tdotopserrors1.nim(16, 7) Error: type mismatch: got <Bar, >
but expected one of:
template `.`(a: Foo; b: untyped): untyped
  first type mismatch at position: 1
  required type for a: Foo
  but expression 'b' is of type: Bar

expression: `.`(b, x)

I just reread #13063 and it states: in addition to the above errmsg Error: type mismatch: got ...

The times I have debugged the compiler, I've really needed a debugger. However, if you set a breakpoint somwhere, it will get hit a bazillion times before it gets to the point where the sample code of interest is being compiled.
If you have lldb, then you may be interested in something I've been toying with.
I have a branch named debugger in my Nim repo: https://github.com/quantimnot/Nim.git
It has some modifications to the compiler source, vscode launch config (for CodeLLDB extension), and lldb scripts that ease debugging scenarios like yours.
Say you want to debug how a specific line is compiled.
Set a breakpoint somewhere of interest, let's say semcall.resolveOverloads. Place your cursor on that line and then launch the debugger. For example:

type Foo = object
template `.`(a: Foo, b: untyped): untyped = 123
type Bar = object
  x1: int
var b: Bar
echo b.x # put your cursor here and then hit F5 to start the debugger

The debugger will now skip that breakpoint until module tdotopserrors1, line (whatever line your cursor was on) is being compiled.

@treeform
Copy link
Contributor Author

treeform commented Nov 20, 2021

Should errors for . and ? be different? I think yes. The dot operator is way too common. Main reason I want to fix this error is that I define the swizzle operator in vmath ( https://github.com/treeform/vmath/blob/master/src/vmath.nim#L556 ), but now every typo I make says, hey you might want to swizzle here. No I don't! Its very annoying and very confusing.

The dot operator is really nice but because it shows up in every error now, makes me not want to use it.

@stale
Copy link

stale bot commented Nov 22, 2022

This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Nov 22, 2022
@metagn
Copy link
Collaborator

metagn commented Nov 29, 2022

#13063 is fixed now (I think), so should be fine to close.

@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Nov 29, 2022
@ringabout ringabout closed this Nov 29, 2022
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.

4 participants