-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Make StringRef
ctor from UnsafePointer[Byte]
keyword only
#3698
Conversation
b1e538e
to
359fbef
Compare
I am curious why implicit conversions are present in Mojo at all? It seems that it is source of a lot of bugs |
@gryznar Even though I'm not a fan of implicit conversions, they seem to be necessary to model things like literals and mimic Python behaviour in the dynamic portion. However, I do agree that we should be able to control them, and only opt-in to implicit conversion when creating a constructor (#1310). |
This issue should be addressed first IMHO, because switching to keyword-only treats symptoms, not cause |
This prevents accidental `UnsafePointer[Byte]` to `String` implicit conversion through `String` ctor from `StringRef`. Signed-off-by: Yiwu Chen <[email protected]>
359fbef
to
d322b84
Compare
Can you elaborate here? For |
@JoeLoser I was always under the impression that it worked this way. I must have mixed it up with another struct. That said, the unsafe constructors from pointers are really a mess, and I find myself having to look up the keyword names every time. Could we adopt a convention like
|
Agreed, they're wildly inconsistent. +1 to your proposed convention - feel free to open a PR. I'm also +1 for making them all (including |
@JoeLoser I think this one is ready. The CI failure is caused by some Conda issues. |
!sync |
Looks good still, we'll just need to fix up our internal usage before this lands/merges internally. I'm on PTO tomorrow, but can look on Monday likely. |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
…keyword only (#49581) [External] [stdlib] Make `StringRef` ctor from `UnsafePointer[Byte]` keyword only This issues was reported by `@aurelian`(@diocletiann) on Discord. This prevents accidental `UnsafePointer[Byte]` to `String` implicit conversion through `String` ctor from `StringRef`. Make this explicit by explicitly constructing the `StringRef` with the keyword-only constructor. Co-authored-by: soraros <[email protected]> Closes #3698 MODULAR_ORIG_COMMIT_REV_ID: 44c1e061db833fff3cf261f2b6eabfcbef6e1591
Landed in 8767f4d! Thank you for your contribution 🎉 |
…keyword only (#49581) [External] [stdlib] Make `StringRef` ctor from `UnsafePointer[Byte]` keyword only This issues was reported by `@aurelian`(@diocletiann) on Discord. This prevents accidental `UnsafePointer[Byte]` to `String` implicit conversion through `String` ctor from `StringRef`. Make this explicit by explicitly constructing the `StringRef` with the keyword-only constructor. Co-authored-by: soraros <[email protected]> Closes modularml#3698 MODULAR_ORIG_COMMIT_REV_ID: 44c1e061db833fff3cf261f2b6eabfcbef6e1591
…keyword only (#49581) [External] [stdlib] Make `StringRef` ctor from `UnsafePointer[Byte]` keyword only This issues was reported by `@aurelian`(@diocletiann) on Discord. This prevents accidental `UnsafePointer[Byte]` to `String` implicit conversion through `String` ctor from `StringRef`. Make this explicit by explicitly constructing the `StringRef` with the keyword-only constructor. Co-authored-by: soraros <[email protected]> Closes #3698 MODULAR_ORIG_COMMIT_REV_ID: 44c1e061db833fff3cf261f2b6eabfcbef6e1591
This issues was reported by
@aurelian
(@diocletiann) on Discord.This prevents accidental
UnsafePointer[Byte]
toString
implicit conversion throughString
ctor fromStringRef
.@JoeLoser Should we make the constructor from pointer+length keyword only as well, following
String
?