Skip to content

Commit

Permalink
Use values from the first module when unifying modules.
Browse files Browse the repository at this point in the history
Fixes #736
  • Loading branch information
gdotdesign committed Feb 17, 2025
1 parent 4c63e77 commit 48bd126
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
47 changes: 47 additions & 0 deletions spec/errors/global_name_conflict
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Main {
fun message() : String {
"Hello, world!"
}
}

component Main {
fun render : Html {
<div>"#{Main.message()}"</div>
}
}
--------------------------------------------------------------------------------
░ ERROR (GLOBAL_NAME_CONFLICT) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

There is already a module with the name: Main

You are trying to define something with the same name here:

┌ errors/global_name_conflict:7:1
├───────────────────────────────────
3│ "Hello, world!"
4│ }
5│ }
6│
│ ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
7│ component Main {
8│ fun render : Html {
9│ <div>"#{Main.message()}"</div>
10│ }
11│ }
│ ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃

The module is defined here:

┌ errors/global_name_conflict:1:1
├───────────────────────────────────
│ ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
1│ module Main {
2│ fun message() : String {
3│ "Hello, world!"
4│ }
5│ }
│ ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃
6│
7│ component Main {
8│ fun render : Html {
9│ <div>"#{Main.message()}"</div>
8 changes: 4 additions & 4 deletions src/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ module Mint
# TODO: We may need to store each modules name node for
# future features, but for now we just store the first
comment: modules.compact_map(&.comment).first?,
file: Parser::File.new(contents: "", path: ""),
functions: modules.flat_map(&.functions),
constants: modules.flat_map(&.constants),
from: Parser::Location.new,
to: Parser::Location.new,
comments: modules.first.comments,
file: modules.first.file,
from: modules.first.from,
name: modules.first.name,
comments: [] of Comment)
to: modules.first.to)
end

@unified_locales =
Expand Down

0 comments on commit 48bd126

Please sign in to comment.