diff --git a/macros/answers/answerHints.pl b/macros/answers/answerHints.pl index 2df9a6ab76..4da47e88ee 100644 --- a/macros/answers/answerHints.pl +++ b/macros/answers/answerHints.pl @@ -144,13 +144,13 @@ sub AnswerHints { cmp_options => [], @options, ); - next if $options{checkTypes} && $correct->type ne $student->type; next if !$options{processPreview} && $ans->{isPreview}; $wrongList = [$wrongList] unless ref($wrongList) eq 'ARRAY'; foreach my $wrong (@{$wrongList}) { if (ref($wrong) eq 'CODE') { - if (($ans->{score} < 1 || $options{checkCorrect}) + if ((!$options{checkTypes} || $correct->type eq $student->type) + && ($ans->{score} < 1 || $options{checkCorrect}) && ($ans->{ans_message} eq "" || $options{replaceMessage})) { # Make the call to run the function inside an eval to trap errors @@ -166,16 +166,12 @@ sub AnswerHints { } } } else { - $wrong = Value::makeValue($wrong); - if ( - ( - $ans->{score} < 1 - || $options{checkCorrect} - || AnswerHints::Compare($correct, $wrong, $ans) - ) - && ($ans->{ans_message} eq "" || $options{replaceMessage}) - && AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} }) - ) + unless (Value::isValue($wrong)) { + $wrong = main::Formula($wrong); + $wrong = $wrong->{tree}->Compute if $wrong->{tree}{canCompute}; + } + if (($ans->{ans_message} eq "" || $options{replaceMessage}) + && AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} })) { $ans->{ans_message} = $ans->{error_message} = $message; $ans->{score} = $options{score} if defined $options{score}; @@ -197,13 +193,13 @@ package AnswerHints; # and returns true if the two values match and false otherwise. # sub Compare { - my $self = shift; - my $other = shift; - my $ans = shift; - $ans = bless { %{$ans}, @_ }, ref($ans); # make a copy + my ($self, $other, $ans, @options) = @_; + return 0 unless $self->typeMatch($other); # make sure these can be compared + $ans = bless { %{$ans}, @options }, ref($ans); # make a copy $ans->{typeError} = 0; $ans->{ans_message} = $ans->{error_message} = ""; $ans->{score} = 0; + if (sprintf("%p", $self) ne sprintf("%p", $ans->{correct_value})) { $ans->{correct_ans} = $self->string; $ans->{correct_value} = $self;