Skip to content

Conversation

@ltzmaxwell
Copy link
Contributor

@ltzmaxwell ltzmaxwell commented Dec 3, 2025

this PR improves the error message for comparison mismatch that mentioned in #4911.

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Dec 3, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: ltzmaxwell/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

❌ Patch coverage is 70.58824% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/type_check.go 61.11% 4 Missing and 3 partials ⚠️
gnovm/pkg/gnolang/preprocess.go 78.57% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Kouteki Kouteki moved this from Triage to In Review in 🧙‍♂️Gno.land development Dec 4, 2025
@Kouteki Kouteki requested a review from thehowl December 4, 2025 18:00
Comment on lines 737 to 740
err := checkAssignableTo(x, xt, dt)
if err != nil {
panic(fmt.Sprintf("invalid operation: %v (mismatched types %v and %v)", x, xt, dt))
}
Copy link
Member

@MikaelVallenet MikaelVallenet Dec 4, 2025

Choose a reason for hiding this comment

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

Should we wrap the error in the panic message ?
We may loose some information isn't ? Looks fine to me since the message indicate the position and show both types so it's enough to understand where & what is the problem.

Also in preprocess.go we show this message, should we have make the panic messages similar for consistence ?

if checkAssignableTo(n, tt, st) != nil {
	panic(
		fmt.Sprintf(
			"cannot use %v (value of type %s) as %s value in assignment",
			valueExpr.String(),
			tt.String(),
			st.String(),
		),
	)
}

Also what about editing directly assertAssignableTo to print your improved message instead doing it specifically at one place.

Copy link
Contributor Author

@ltzmaxwell ltzmaxwell Dec 5, 2025

Choose a reason for hiding this comment

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

Should we wrap the error in the panic message ?

I think the low-level message is useful for debugging, but not for end users. We should log it instead of returning. :51625b8

Also in preprocess.go we show this message, should we have make the panic messages similar for consistence ?

it looks the correct, see gnovm/tests/files/assign33.gno.

Also what about editing directly assertAssignableTo to print your improved message instead doing it specifically at one place.

for me it still make sense that it provides lower-level infos.

}

func assertAssignableTo(n Node, xt, dt Type) {
func mustAssignableTo(n Node, xt, dt Type) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: but why must overt assert
IMO, i use must when i expect something in return like: "mustGetEntity" and assert when i don't expect a return but it's how i see it, just is there a reason behind this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for me, must is more of a convention from Go stdlibs, e.g.

regexp.MustCompile(...) (Panics if regex is invalid)
template.Must(...) (Panics if template parsing fails)

while assert is always used in unit test, e.g. testify/assert.

Copy link
Member

@MikaelVallenet MikaelVallenet left a comment

Choose a reason for hiding this comment

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

LGTM

@ltzmaxwell ltzmaxwell changed the title WIP chore(gnovm): optimize err msg chore(gnovm): optimize err msg Dec 5, 2025
Comment on lines +740 to +746
err := checkAssignableTo(x, xt, dt)
if err != nil {
if debug {
debug.Printf("checkAssignableTo fail: %v\n", err)
}
panic(fmt.Sprintf("invalid operation: %v (mismatched types %v and %v)", x, xt, dt))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

log low-level error and return user friendly info, which is more in line with Go.

Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

looks like an improvement, but i would avoid re-writing the full expression in the error

if debug {
debug.Printf("checkAssignableTo fail: %v\n", err)
}
panic(fmt.Sprintf("invalid operation: %v (mismatched types %v and %v)", x, xt, dt))
Copy link
Member

Choose a reason for hiding this comment

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

security-wise, we should maybe avoid panicking with the whole expression, as it might be very deep. what about making the error "types %v and %v are not comparable"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🤖 gnovm Issues or PRs gnovm related

Projects

Status: No status
Status: In Review

Development

Successfully merging this pull request may close these issues.

4 participants