Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e637f567784e
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 10ad407046cc
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 3, 2016

  1. Copy the full SHA
    8960fb9 View commit details
  2. Compiler: hide redundant initialize error trace segment

    Ary Borenszweig committed Dec 3, 2016
    Copy the full SHA
    10ad407 View commit details
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ module Crystal
end
msg = msg.join " "

node.raise "can't expand macro: #{msg}"
node.raise msg, exception_type: MacroRaiseException
end

def interpret_run(node)
9 changes: 8 additions & 1 deletion src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
@@ -926,7 +926,14 @@ class Crystal::Call
yield
rescue ex : Crystal::Exception
if obj = @obj
raise "instantiating '#{obj.type}##{name}(#{args.map(&.type).join ", "})'", ex
if name == "initialize"
# Avoid putting 'initialize' in the error trace
# because it's most likely that this is happening
# inside a generated 'new' method
::raise ex
else
raise "instantiating '#{obj.type}##{name}(#{args.map(&.type).join ", "})'", ex
end
else
raise "instantiating '#{name}(#{args.map(&.type).join ", "})'", ex
end
11 changes: 11 additions & 0 deletions src/compiler/crystal/semantic/exception.cr
Original file line number Diff line number Diff line change
@@ -31,6 +31,14 @@ module Crystal
end

def initialize(message, @line, @column : Int32, @filename, @size, @inner = nil)
# If the inner exception is a macro raise, we replace this exception's
# message with that message. In this way the error message will
# look like a regular message produced by the compiler, and not
# because of an incorrect macro expansion.
if inner.is_a?(MacroRaiseException)
message = inner.message
@inner = nil
end
super(message)
end

@@ -283,6 +291,9 @@ module Crystal
class UndefinedMacroMethodError < TypeException
end

class MacroRaiseException < TypeException
end

class Program
def undefined_global_variable(node, similar_name)
common = String.build do |str|
25 changes: 14 additions & 11 deletions src/compiler/crystal/semantic/semantic_visitor.cr
Original file line number Diff line number Diff line change
@@ -221,10 +221,8 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
def expand_macro(node, raise_on_missing_const = true, first_pass = false)
if expanded = node.expanded
@exp_nest -= 1
begin
eval_macro(node) do
expanded.accept self
rescue ex : Crystal::Exception
node.raise "expanding macro", ex
end
@exp_nest += 1
return true
@@ -277,11 +275,10 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
end

def expand_macro(the_macro, node, mode = nil)
begin
expanded_macro = yield
rescue ex : Crystal::Exception
node.raise "expanding macro", ex
end
expanded_macro =
eval_macro(node) do
yield
end

mode ||= if @in_c_struct_or_union
Program::MacroExpansionMode::Normal
@@ -353,10 +350,8 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor

def expand_inline_macro(node, mode = nil)
if expanded = node.expanded
begin
eval_macro(node) do
expanded.accept self
rescue ex : Crystal::Exception
node.raise "expanding macro", ex
end
return expanded
end
@@ -373,6 +368,14 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
generated_nodes
end

def eval_macro(node)
yield
rescue ex : MacroRaiseException
node.raise ex.message, exception_type: MacroRaiseException
rescue ex : Crystal::Exception
node.raise "expanding macro", ex
end

def check_valid_attributes(node, valid_attributes, desc)
attributes = @attributes
return unless attributes