Commit 485c8ed
committed
Fix two alias-handling issues found in review
* update_aliases persisted const.is_alias_for from the lazy
resolved_alias_target lookup before the collision guard ran. When
a real class already lived at the destination, the alias copy was
correctly skipped but the constant was still mismarked, so
Stats#report_constants and Constant#marshal_dump observed the
alias relationship for an object the guard had just protected.
Move the persistence below the guard so skipped aliases also skip
the persistence.
* In the prism parser, add_constant resolved owner/name from the
full constant path but called @container.add_module_alias on the
outer lexical container. For Outer::Foo = Bar parsed at top level,
this registered the alias copy as classes_hash['Foo'] (using the
container's child_name) instead of 'Outer::Foo', leaving a stray
top-level entry that update_aliases later duplicated under the
correct namespace. Call owner.add_module_alias instead. The
ripper parser already handles this correctly because parse_constant
reassigns its container to the resolved nested module.
Tests:
* test_constant_alias_collision_does_not_mismark_constant_as_alias
asserts Foo's constant ends up with is_alias_for=nil when a real
Foo class already exists alongside Foo = Bar.
* test_qualified_constant_alias_registers_in_owner_namespace
asserts Outer::Foo = Bar registers only at classes_hash['Outer::Foo']
and does not leak a top-level Foo entry.1 parent 1846a8a commit 485c8ed
3 files changed
Lines changed: 40 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
| 851 | + | |
858 | 852 | | |
859 | 853 | | |
860 | 854 | | |
| |||
882 | 876 | | |
883 | 877 | | |
884 | 878 | | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
885 | 884 | | |
886 | 885 | | |
887 | 886 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
793 | | - | |
| 793 | + | |
794 | 794 | | |
795 | 795 | | |
796 | 796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1828 | 1828 | | |
1829 | 1829 | | |
1830 | 1830 | | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
1831 | 1864 | | |
1832 | 1865 | | |
1833 | 1866 | | |
| |||
0 commit comments