Closed
Description
I forget if there's already a bug on this, but it would be nice if, when you wrote A.B
and A
doesn't have a field named B
, but does have a nullary method named B
, the compiler gave a hint like "did you mean to write A.B()
?" It could also do vice versa (if you write A.B()and
Ais a class with field
B, it could ask "did you mean
A.B```?)
I ran into this in trans, where I have frequently written bcx.ccx
instead of bcx.ccx()
.
Activity
catamorphism commentedon Nov 8, 2012
Test:
The error message is better now than it was:
in that it suggests there is a method named
mew
. But it could still be improved. (The intention may not have been to take the method's value; it seems more likely that the programmer thought it wasn't a method at all.)catamorphism commentedon Jan 20, 2013
My previous comment still holds. It would be great if you would see the "try writing an anonymous function" hint for something like
f(kitty.mew, xs)
and instead see a "did you mean to writekitty.mew()
?" in situations like this one.bblum commentedon Jul 3, 2013
I'd also like to see one when trying to call a function-typed struct field:
emits
error: type
Foodoes not implement any method in scope named
f``.It'd be nice if it tried to see if it could auto-deref to a struct field, and if so, say
to use a struct field as a function, write
(f.f)()``.pnkfelix commentedon Jan 9, 2014
A nice idea. Assigning P-low.
vks commentedon Aug 29, 2014
Currently
gives
which is pretty close to the proposed behavior.
Replacing the
main
wihyields the same as before (i.e. does not suggest removing the
()
):huonw commentedon Mar 2, 2015
Updated the example @vks gives:
which now prints
It's nice that the note is there, but the text is suboptimal:
kitty.x
isn't a function.Nashenas88 commentedon Jun 13, 2015
I'm working on a fix for this, but I'm struggling with the final portion. With this code:
I get the output:
My current changes are here. I'm not sure if it's possible to have the output say "kitty.func" and "kitty.x" with the input to the
report_error
function. Any ideas? Or should I just keep the message in the same format as it is now and output "s.func" and "did you mean to writes.x
?"?Edit:
Ideally, I would like to output:
I'm wondering if that's at all possible, especially because instead of
kitty
, there might be an expression.Nashenas88 commentedon Jun 14, 2015
I got around that error message. Now I'm making sure the previous
(kitty.func)(...)
message is displayed under the proper circumstances.Auto merge of #26305 - Nashenas88:field-method-message-2392, r=eddyb
6 remaining items