Skip to content

Commit e7ae57e

Browse files
Omar Qureshiclaude
andcommitted
fix(ruby): const-aware naming and deprecation-based collision resolution
Two real generator gaps surfaced as runtime-broken bindings for the jsii-calc fixtures `StaticHelloParent`, `Statics`, `UpcasingReflectable`, `DisappointingCollectionSource`, and `TwoMethodsWithSimilarCapitalization`: 1. `property` + `PROPERTY` (and friends like `foo`/`Foo`/`BAR`/`zooBar`) both snake_cased to the same Ruby identifier, so the second `def` silently overwrote the first. Now `const: true` properties take an UPPER_SNAKE_CASE form (`maybeList` -> `MAYBE_LIST`, `PROPERTY` stays `PROPERTY`), matching Python's `toPythonPropertyName(name, constant)`. Ruby parses `Foo.PROPERTY` and `Foo.property` as distinct method calls, so both coexist without ambiguity. 2. `fooBar`/`fooBAR` and `toIsoString`/`toISOString` still collide after step 1 because they aren't const. Mirror Python's `prepareMembers`: drop deprecated members on collision and keep the single non-deprecated one. Throw if the inputs leave the bug visible (multiple non-deprecated, or all deprecated). Side effects: - Drop `assertNoRubyNameCollisions` / `assertNoEnumConstCollisions`; their warn-and-last-wins behavior is replaced by the dedup pass which throws on truly irreconcilable cases. - Drop the async-static warning. Python documents the same gap (`PromiseNothing.promise_it` is `#`-commented "TODO: code-gen is incorrect for static async"), and a real fix requires extending `BeginRequest` to accept an `fqn` form — a kernel protocol change, not a Ruby-side fix. - Update rspec assertions for the four constants that moved from snake_case to UPPER_SNAKE_CASE. 166 ruby spec tests pass, 32 ruby pacmak snapshots pass, 63 version-utils tests pass, 110 kernel naming tests pass. Zero generator warnings on the jsii-calc closure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1e0e4c5 commit e7ae57e

5 files changed

Lines changed: 263 additions & 187 deletions

File tree

packages/@jsii/ruby-runtime-test/spec/classes_and_interfaces_spec.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ def initialize(value)
6565
end
6666

6767
it 'supports constants' do
68-
expect(JsiiCalc::Statics.foo).to eq('hello')
69-
expect(JsiiCalc::Statics.const_obj.hello).to eq('world')
70-
expect(JsiiCalc::Statics.bar).to eq(1234)
71-
expect(JsiiCalc::Statics.zoo_bar['hello']).to eq('world')
68+
# const properties take an UPPER_SNAKE_CASE form in Ruby (matches Python's
69+
# `toPythonPropertyName(name, constant=true)`) so they don't collide with
70+
# a sibling snake_case property of the same lowercased name.
71+
expect(JsiiCalc::Statics.FOO).to eq('hello')
72+
expect(JsiiCalc::Statics.CONST_OBJ.hello).to eq('world')
73+
expect(JsiiCalc::Statics.BAR).to eq(1234)
74+
expect(JsiiCalc::Statics.ZOO_BAR['hello']).to eq('world')
7275
end
7376
end
7477
describe 'Interfaces' do

packages/@jsii/ruby-runtime-test/spec/modules_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def initialize(value)
4949
describe 'Dependency Submodule Types' do
5050
it 'are usable' do
5151
subject = JsiiCalc::UpcasingReflectable.new('foo' => 'bar')
52-
expect(JsiiCalc::UpcasingReflectable.reflector.as_map(subject)).to eq('FOO' => 'bar')
52+
expect(JsiiCalc::UpcasingReflectable.REFLECTOR.as_map(subject)).to eq('FOO' => 'bar')
5353
end
5454
end
5555
describe 'Submodule classes' do

packages/@jsii/ruby-runtime-test/spec/types_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ def initialize(value)
223223
end
224224

225225
it 'null is a valid optional list' do
226-
expect(JsiiCalc::DisappointingCollectionSource.maybe_list).to be_nil
226+
expect(JsiiCalc::DisappointingCollectionSource.MAYBE_LIST).to be_nil
227227
end
228228

229229
it 'null is a valid optional map' do
230-
expect(JsiiCalc::DisappointingCollectionSource.maybe_map).to be_nil
230+
expect(JsiiCalc::DisappointingCollectionSource.MAYBE_MAP).to be_nil
231231
end
232232
end
233233
end

0 commit comments

Comments
 (0)