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

Replace the class keyword with the type keyword #779

Closed
6 tasks done
yorickpeterse opened this issue Nov 21, 2024 · 0 comments
Closed
6 tasks done

Replace the class keyword with the type keyword #779

yorickpeterse opened this issue Nov 21, 2024 · 0 comments
Assignees
Labels
compiler Changes related to the compiler feature New things to add to Inko, such as a new standard library module
Milestone

Comments

@yorickpeterse
Copy link
Collaborator

yorickpeterse commented Nov 21, 2024

Description

In #778 I'm introducing support for user-defined stack allocated types. In pretty much all languages out there that have a notion of classes, the class keyword is typically used for a heap allocated type that you address through a pointer, and something like a struct keyword is used (if supported at all) for stack types.

This means that seeing class inline Foo { ... } is a bit odd, because class might have you believe it's a heap type, while inline means it's in fact a stack type.

To resolve this, we'll replace the class keyword with the type keyword. So instead of this:

class User { ... }
class inline Number { ... }

You'd write the following:

type User { ... }
type inline Number { ... }

For traits we'll continue to use the trait keyword as there's no benefit to changing it.

TODO

  • Support both class and type at the parser level
  • Update the Tree sitter grammar to support both class and type
  • Update Vim syntax file
  • Update VS Code extension
  • Update the code formatter to replace class with type automatically
  • Update the documentation

Related work

No response

@yorickpeterse yorickpeterse added feature New things to add to Inko, such as a new standard library module compiler Changes related to the compiler labels Nov 21, 2024
@yorickpeterse yorickpeterse added this to the 0.18.0 milestone Nov 21, 2024
@yorickpeterse yorickpeterse self-assigned this Nov 21, 2024
yorickpeterse added a commit that referenced this issue Dec 23, 2024
Now that types are no longer guaranteed to go on the heap, the use of
"class" can be confusing as this is typically used for types that go on
the heap. In addition, our types weren't really traditional classes to
begin with due to the lack of support for inheritance.

The `class` keyword is still supported but is now deprecated, and the
`fmt` command automatically replaces it with the new `type` keyword.

This fixes #779.

Changelog: changed
yorickpeterse added a commit that referenced this issue Dec 24, 2024
Now that types are no longer guaranteed to go on the heap, the use of
"class" can be confusing as this is typically used for types that go on
the heap. In addition, our types weren't really traditional classes to
begin with due to the lack of support for inheritance.

The `class` keyword is still supported but is now deprecated, and the
`fmt` command automatically replaces it with the new `type` keyword.

This fixes #779.

Changelog: changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes related to the compiler feature New things to add to Inko, such as a new standard library module
Projects
None yet
Development

No branches or pull requests

1 participant