[#108771] [Ruby master Bug#18816] Ractor segfaulting MacOS 12.4 (aarch64 / M1 processor) — "brodock (Gabriel Mazetto)" <noreply@...>

Issue #18816 has been reported by brodock (Gabriel Mazetto).

8 messages 2022/06/05

[#108802] [Ruby master Feature#18821] Expose Pattern Matching interfaces in core classes — "baweaver (Brandon Weaver)" <noreply@...>

Issue #18821 has been reported by baweaver (Brandon Weaver).

9 messages 2022/06/08

[#108822] [Ruby master Feature#18822] Ruby lack a proper method to percent-encode strings for URIs (RFC 3986) — "byroot (Jean Boussier)" <noreply@...>

Issue #18822 has been reported by byroot (Jean Boussier).

18 messages 2022/06/09

[#108937] [Ruby master Bug#18832] Suspicious superclass mismatch — "fxn (Xavier Noria)" <noreply@...>

Issue #18832 has been reported by fxn (Xavier Noria).

16 messages 2022/06/15

[#108976] [Ruby master Misc#18836] DevMeeting-2022-07-21 — "mame (Yusuke Endoh)" <noreply@...>

Issue #18836 has been reported by mame (Yusuke Endoh).

12 messages 2022/06/17

[#109043] [Ruby master Bug#18876] OpenSSL is not available with `--with-openssl-dir` — "Gloomy_meng (Gloomy Meng)" <noreply@...>

Issue #18876 has been reported by Gloomy_meng (Gloomy Meng).

18 messages 2022/06/23

[#109052] [Ruby master Bug#18878] parse.y: Foo::Bar {} is inconsistently rejected — "qnighy (Masaki Hara)" <noreply@...>

Issue #18878 has been reported by qnighy (Masaki Hara).

9 messages 2022/06/26

[#109055] [Ruby master Bug#18881] IO#read_nonblock raises IOError when called following buffered character IO — "javanthropus (Jeremy Bopp)" <noreply@...>

Issue #18881 has been reported by javanthropus (Jeremy Bopp).

9 messages 2022/06/26

[#109063] [Ruby master Bug#18882] File.read cuts off a text file with special characters when reading it on MS Windows — magynhard <noreply@...>

Issue #18882 has been reported by magynhard (Matth辰us Johannes Beyrle).

15 messages 2022/06/27

[#109081] [Ruby master Feature#18885] Long lived fork advisory API (potential Copy on Write optimizations) — "byroot (Jean Boussier)" <noreply@...>

Issue #18885 has been reported by byroot (Jean Boussier).

23 messages 2022/06/28

[#109083] [Ruby master Bug#18886] Struct aref and aset don't trigger any tracepoints. — "ioquatix (Samuel Williams)" <noreply@...>

Issue #18886 has been reported by ioquatix (Samuel Williams).

8 messages 2022/06/29

[#109095] [Ruby master Misc#18888] Migrate ruby-lang.org mail services to Google Domains and Google Workspace — "shugo (Shugo Maeda)" <noreply@...>

Issue #18888 has been reported by shugo (Shugo Maeda).

16 messages 2022/06/30

[ruby-core:108751] [Ruby master Misc#18813] Let Module#autoload be strict about the autoloaded constant

From: "ioquatix (Samuel Williams)" <noreply@...>
Date: 2022-06-01 23:37:58 UTC
List: ruby-core #108751
Issue #18813 has been updated by ioquatix (Samuel Williams).


I support raising an error when this fails to load the right constant. I think we can add a warning in 3.2 and make it an error in 3.3.

----------------------------------------
Misc #18813: Let Module#autoload be strict about the autoloaded constant
https://bugs.ruby-lang.org/issues/18813#change-97810

* Author: fxn (Xavier Noria)
* Status: Open
* Priority: Normal
----------------------------------------
## Introduction

Let's consider

```ruby
module M
  autoload :X, 'x'
end
```

The constants API does not distinguish existing constants from potential constants:

```ruby
M.constants(false)          # => [:X]
M.const_defined?(:X, false) # => true
```

## Expectations

For a `false` inherited flag, the documentation of `Module#constants` says

> Returns an array of the names of the constants accessible in mod.

As a Ruby programmer, that is telling me `X` belongs to `M`, and `M::X` is a valid reference.

Therefore, for coherence, if loading `x.rb` does not define `M::X`, I'd expect that to be a programming error. I'd expect `Module#autoload` to raise `NameError` with an ad-hoc error message in the line of "file '/full/path/to/x.rb' failed to define the constant M::X`.

This does not happen today, `Module#autoload` is a simple trigger that loads a file and execution resumes with whatever side-effects that happened to have. Similar to `Module#const_missing`.

However, to me, `Module#autoload` is different from `Module#const_missing` in a fundamental way. If autoloads were not present in the constants API, both could be equal, but they are present. **For consistency with the constants API**, I believe there has to be a strict expectation. If the autoload does not define `M::X`, the programmer did a mistake and an exception should say so. Zeitwerk [does this](https://github.com/fxn/zeitwerk/blob/5a700a322495398730ed74c6bec8180a75ba404f/lib/zeitwerk/loader/callbacks.rb#L27) by hand nowadays.

There is a patch implementing this in https://github.com/ruby/ruby/pull/5949.

## Backwards Compatibility

Backwards compatibility has to be considered, because some people do, for example:

```ruby
module MyGem
  autoload :OpenSSL, 'openssl'
end
```

While that is technically allowed, in my opinion that idiom is an unnecessary abuse of autoloading. The autoload is not even scoped to your gem, because

```ruby
class MyGem::MyClass
  OpenSSL
end
```

would not work. That autoload should be in the top-level, where `OpenSSL` is going to be defined (assuming the top-level nesting is empty, you know).

My hunch is that such autoloads may technically exist, but this is a very edge feature and very few people know about it. And those that know, may still define autoloads in their natural place. I'd be surprised if it is widely used.

Anyway, in case you'd like this proposal, whether this change deserves a deprecation cycle is totally your call.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread