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

cmd/compile: possible error message improvement #4565

Open
rsc opened this issue Dec 18, 2012 · 6 comments
Open

cmd/compile: possible error message improvement #4565

rsc opened this issue Dec 18, 2012 · 6 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Dec 18, 2012

http://play.golang.org/p/87zosrj611

package main

var x = 10
var y = 0.9 * x

prog.go:4: constant 0.9 truncated to integer

If you don't know that x is an int or that * requires both sides to have the same type,
this is a bit of a leap.

constant 0.9 truncated during conversion to type int (to match x)

might be a little better.
@rsc
Copy link
Contributor Author

rsc commented Mar 12, 2013

Comment 1:

[The time for maybe has passed.]

Labels changed: removed go1.1maybe.

@rsc
Copy link
Contributor Author

rsc commented Jul 30, 2013

Comment 2:

Labels changed: added go1.2maybe.

@rsc
Copy link
Contributor Author

rsc commented Sep 9, 2013

Comment 3:

Labels changed: added go1.3maybe, removed go1.2maybe.

@rsc
Copy link
Contributor Author

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor Author

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added repo-main.

@rsc rsc self-assigned this Dec 4, 2013
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: possible error message improvement cmd/compile: possible error message improvement Jun 8, 2015
@nathany
Copy link
Contributor

nathany commented Mar 4, 2016

I agree that it's a bit of a leap.

constant 0.9 truncated to integer

Compare that to the error when only variables are in the expression. It includes the expression and the types of the variables in question: https://play.golang.org/p/nfZ_xMultw

invalid operation: w * x (mismatched types float64 and int)

I like the idea of including (x) in the error message.

constant truncated: 0.9 * x ...

On the other hand, it's not always clear which variables are the cause when only variables are involved: https://play.golang.org/p/9_EchugdkA

invalid operation: v * w * x (mismatched types float64 and int)

So maybe there's a better way to do that error message as well. What comes to mind is the conversion syntax to indicate the types:

constant 0.9 truncated to integer: 0.9 * int(x)
mismatched types: float64(v) * float64(w) * int(x)

Here's a slightly more complex constants example where it might be nice if the error indicated that w is involved as well as that x is an integer (the reason for the truncation)

const w = 0.9
var x = 10
var z = w * w * x

constant 0.81 truncated to integer
constant 0.81 truncated to integer: w * w * int(x)
constant 0.81 truncated to integer: 0.9 * 0.9 * int(x)

https://play.golang.org/p/wklLBzn6XY

This is my random issue today via CodeTriage.

@rsc rsc removed their assignment Jun 22, 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

No branches or pull requests

2 participants