Project

General

Profile

Actions

Bug #21341

open

`Namespace is not a module (TypeError)` without enabling the namespace

Added by yahonda (Yasuo Honda) about 10 hours ago. Updated about 10 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-05-15T08:25:56Z master 427ede2dde) +PRISM [x86_64-linux]
[ruby-core:122114]

Description

Ruby on Rails test case has the module Namespace.

https://github.com/rails/rails/blob/main/activemodel/test/validators/namespace/email_validator.rb#L5

module Namespace
  class EmailValidator < ::EmailValidator
  end
end

This code fails against Ruby 3.5.0dev without enabling the namespace feature.

Steps to reproduce

$ ruby -ve 'module Namespace; end'

Expected behavior

It should run without errors.

Actual behavior

It raises the TypeError.

$ ruby -ve 'module Namespace; end'
ruby 3.5.0dev (2025-05-15T08:25:56Z master 427ede2dde) +PRISM [x86_64-linux]
-e:1:in '<main>': Namespace is not a module (TypeError)
ruby:0: previous definition of Namespace was here

Raising this TypeError with RUBY_NAMESPACE=1 looks expected to me.

$ RUBY_NAMESPACE=1 ruby -ve 'module Namespace; end'
ruby 3.5.0dev (2025-05-15T08:25:56Z master 427ede2dde) +PRISM [x86_64-linux]
ruby: warning: Namespace is experimental, and the behavior may change in the future!
See doc/namespace.md for known issues, etc.
-e:1:in '<main>': Namespace is not a module (TypeError)
ruby:0: previous definition of Namespace was here

Updated by yahonda (Yasuo Honda) about 10 hours ago

This code comes from a Rails test case, so we can change it if needed. However, there might be other cases to consider.

Updated by yahonda (Yasuo Honda) about 10 hours ago

This only triggers the TypeError for the top-level module Namespace, not when it’s nested inside another module.

$ ruby -ve 'module Foo; module Namespace; end; end'
ruby 3.5.0dev (2025-05-15T08:25:56Z master 427ede2dde) +PRISM [x86_64-linux]
$ RUBY_NAMESPACE=1 ruby -ve 'module Foo; module Namespace; end; end'
ruby 3.5.0dev (2025-05-15T08:25:56Z master 427ede2dde) +PRISM [x86_64-linux]
ruby: warning: Namespace is experimental, and the behavior may change in the future!
See doc/namespace.md for known issues, etc.
$
Actions

Also available in: Atom PDF

Like0
Like0Like0