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

update newtype access syntax #326

Merged
merged 1 commit into from
Nov 8, 2024
Merged

Conversation

Guest0x0
Copy link
Collaborator

@Guest0x0 Guest0x0 commented Nov 8, 2024

No description provided.

Copy link

From the provided git diff output, I observe the following issues related to MoonBit language usage:

  1. Incorrect Field Access for Newtypes:

    • The original code uses id.0 to access the internal representation of a newtype UserId. However, the MoonBit documentation suggests using id._ for this purpose.
    • Affected lines:
      - let uid: Int = id.0
      + let uid: Int = id._
  2. Error Handling with Newtypes:

    • The function f attempts to raise an error using self.0 to access the internal representation of a newtype T. This should be corrected to use self._.
    • Affected lines:
      - fn f(self: T) -> Unit!E { raise E(self.0) }
      + fn f(self: T) -> Unit!E { raise E(self._) }
  3. String Concatenation with Newtypes:

    • In the speak function for the Duck type, the code uses self.0 to access the internal string representation. This should be corrected to use self._.
    • Affected lines:
      - println(self.0 + ": quack!")
      + println(self._ + ": quack!")

These changes ensure that the code adheres to the MoonBit language conventions for accessing the internal representation of newtypes, which is crucial for maintaining consistency and avoiding potential runtime errors.

@Guest0x0 Guest0x0 merged commit 835a69d into main Nov 8, 2024
1 check passed
@Guest0x0 Guest0x0 deleted the Guest0x0/update-newtype-access-syntax branch November 8, 2024 07:18
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

Successfully merging this pull request may close these issues.

1 participant