Skip to content

Implement abstract classes#3

Open
amomchilov wants to merge 2 commits intoAlex/interfacesfrom
Alex/abstract-classes
Open

Implement abstract classes#3
amomchilov wants to merge 2 commits intoAlex/interfacesfrom
Alex/abstract-classes

Conversation

@amomchilov
Copy link
Contributor

No description provided.

This was referenced Feb 19, 2026
@amomchilov
Copy link
Contributor Author

amomchilov commented Feb 19, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@amomchilov amomchilov force-pushed the Alex/interfaces branch 2 times, most recently from cf42ec7 to 998bf60 Compare February 19, 2026 23:25
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from f15c512 to 1c4ff1e Compare February 20, 2026 00:32
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from 1c4ff1e to d755cfd Compare February 20, 2026 16:34
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from d755cfd to 4d2d914 Compare February 20, 2026 17:08
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch 2 times, most recently from aab5377 to f0da94c Compare February 21, 2026 00:19
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from f0da94c to ae69e75 Compare February 23, 2026 23:18
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from ae69e75 to 0b95499 Compare February 23, 2026 23:53
@amomchilov amomchilov force-pushed the Alex/interfaces branch 2 times, most recently from a66d3fb to 860b7f9 Compare February 24, 2026 01:33
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from 0b95499 to 51dcab6 Compare February 24, 2026 01:33
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from 51dcab6 to 2dae200 Compare February 24, 2026 23:32
@amomchilov amomchilov mentioned this pull request Feb 24, 2026
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from 2dae200 to b2735fd Compare February 25, 2026 00:06
@amomchilov amomchilov marked this pull request as ready for review February 25, 2026 15:07
@amomchilov amomchilov requested a review from a team February 25, 2026 15:07
#: self as Class[top]

if respond_to?(:__original_new_impl) # This is true for the abstract classes themselves, and false for their subclasses.
raise CannotInstantiateAbstractClassError, "#{self.class.name} is declared as abstract; it cannot be instantiated"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a bug here: self inside AbstractClass#new is the abstract class itself (e.g. Widget), so self.class is Class, not the abstract class. The error message would print "Class is declared as abstract" instead of the actual class name.

I wonder if we should use name instead?

Suggested change
raise CannotInstantiateAbstractClassError, "#{self.class.name} is declared as abstract; it cannot be instantiated"
raise CannotInstantiateAbstractClassError, "#{name} is declared as abstract; it cannot be instantiated"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I have to add tests for abstract class methods, and I'll verify their name is correct in the message.

#: self as HasAbstractMethods & Module[top]

result = @__abstract_methods
result = @__abstract_methods #: Set[Symbol]?
Copy link
Contributor

Choose a reason for hiding this comment

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

My concern here is that result holds a direct reference to @__abstract_methods, so the subsequent result.merge(methods) on line 32 mutates the underlying ivar Set in place. After the first include_super: true call, @__abstract_methods would contain all ancestor methods too, meaning future calls would return incorrect (and growing) results.

I wonder if we should dup it here to avoid the mutation?

Suggested change
result = @__abstract_methods #: Set[Symbol]?
result = @__abstract_methods&.dup #: Set[Symbol]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This hasn't been an issue with the current test suite, but I'll look into it!

@amomchilov amomchilov changed the base branch from Alex/interfaces to graphite-base/3 February 25, 2026 17:52
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch from b2735fd to dac855d Compare February 25, 2026 18:15
@amomchilov amomchilov changed the base branch from graphite-base/3 to Alex/interfaces February 25, 2026 18:15
@amomchilov amomchilov force-pushed the Alex/abstract-classes branch 2 times, most recently from 904ba88 to a60ddb0 Compare February 25, 2026 18:35
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.

2 participants