Skip to content

compiler: Support slice expressions for string #3916

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

Merged
merged 3 commits into from
May 29, 2025

Conversation

fyfyrchik
Copy link
Contributor

@fyfyrchik fyfyrchik commented May 22, 2025

According to code, compiler currently supports slice expressions only for []byte and triggers an error otherwise. However, using them with string type fails silently:

s := "abc"
return s[:2] == "ab" // oops, false!

This happens, because the resulting type for this operation is Buffer, but "ab" has type ByteString. So, we have 2 options:

  • improve validation and trigger an error,
  • or just support strings.

This commit implements the latter.

@fyfyrchik fyfyrchik force-pushed the compiler-substring branch 3 times, most recently from 78c1e8f to b37dc02 Compare May 22, 2025 13:51
Copy link

codecov bot commented May 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.80%. Comparing base (92523bb) to head (5e0c961).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3916      +/-   ##
==========================================
+ Coverage   81.78%   81.80%   +0.02%     
==========================================
  Files         345      345              
  Lines       48852    48854       +2     
==========================================
+ Hits        39954    39966      +12     
+ Misses       7229     7222       -7     
+ Partials     1669     1666       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

fyfyrchik added 3 commits May 23, 2025 10:44
According to code, compiler currently supports slice expressions
only for `[]byte` and triggers an error otherwise. However, using
them with `string` type fails silently:
```
s := "abc"
return s[:2] == "ab" // oops, false!
```

This happens, because the resulting type for this operation is `Buffer`,
but "ab" has type `ByteString`. So, we have 2 options:
- improve validation and trigger an error,
- or just support strings.

This commit implements the latter.

Signed-off-by: Evgenii Stratonikov <[email protected]>
Otherwise, we get an error:
```
-: main module (github.com/nspcc-dev/neo-go) does not contain package github.com/nspcc-dev/neo-go/pkg/compiler
```

Signed-off-by: Evgenii Stratonikov <[email protected]>
@fyfyrchik fyfyrchik force-pushed the compiler-substring branch from b37dc02 to 5e0c961 Compare May 23, 2025 07:45
@fyfyrchik
Copy link
Contributor Author

Codecov failed because TestSubcliceCompound() was bad, see the updated version.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

@AnnaShaleva AnnaShaleva added this to the v0.110.0 milestone May 29, 2025
@AnnaShaleva AnnaShaleva added compiler Go smart contract compiler enhancement Improving existing functionality labels May 29, 2025
@AnnaShaleva AnnaShaleva merged commit 360fb10 into nspcc-dev:master May 29, 2025
33 of 34 checks passed
@fyfyrchik fyfyrchik deleted the compiler-substring branch May 29, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Go smart contract compiler enhancement Improving existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants