mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 22:10:15 +03:00
Type of UnresolvedSymbol is Function (#6284)
`Meta.is_a` and `Meta.type_of` now recognize UnresolvedSymbol. Closes #6277.
This commit is contained in:
parent
e68d16a38e
commit
f720bd2516
@ -3622,7 +3622,7 @@ class RuntimeServerTest
|
||||
contextId,
|
||||
Seq(
|
||||
Api.ExecutionResult.Diagnostic.error(
|
||||
"Type error: expected `that` to be Number, but got quux (Unresolved_Symbol).",
|
||||
"Type error: expected `that` to be Number, but got Function.",
|
||||
Some(mainFile),
|
||||
Some(model.Range(model.Position(11, 8), model.Position(11, 17))),
|
||||
None,
|
||||
|
@ -12,6 +12,7 @@ import com.oracle.truffle.api.profiles.ConditionProfile;
|
||||
import org.enso.interpreter.epb.runtime.PolyglotExceptionProxy;
|
||||
import org.enso.interpreter.epb.runtime.PolyglotProxy;
|
||||
import org.enso.interpreter.runtime.EnsoContext;
|
||||
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
|
||||
import org.enso.interpreter.runtime.callable.atom.AtomConstructor;
|
||||
import org.enso.interpreter.runtime.data.Type;
|
||||
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
|
||||
@ -66,6 +67,12 @@ public abstract class IsValueOfTypeNode extends Node {
|
||||
return checkParentTypes(numbers.getBigInteger(), expectedType);
|
||||
}
|
||||
|
||||
@Specialization
|
||||
boolean doUresolvedSymbol(Type expectedType, UnresolvedSymbol value) {
|
||||
var funTpe = EnsoContext.get(this).getBuiltins().function();
|
||||
return expectedType == funTpe;
|
||||
}
|
||||
|
||||
@ExplodeLoop
|
||||
private boolean checkParentTypes(Type actual, Type expected) {
|
||||
for (; ; ) {
|
||||
|
@ -13,6 +13,7 @@ import org.enso.interpreter.dsl.BuiltinMethod;
|
||||
import org.enso.interpreter.epb.runtime.PolyglotProxy;
|
||||
import org.enso.interpreter.runtime.EnsoContext;
|
||||
import org.enso.interpreter.runtime.builtin.Builtins;
|
||||
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
|
||||
import org.enso.interpreter.runtime.data.text.Text;
|
||||
import org.enso.interpreter.runtime.error.DataflowError;
|
||||
import org.enso.interpreter.runtime.error.PanicException;
|
||||
@ -36,6 +37,11 @@ public abstract class TypeOfNode extends Node {
|
||||
return TypeOfNodeGen.create();
|
||||
}
|
||||
|
||||
@Specialization
|
||||
Object doUnresolvedSymbol(UnresolvedSymbol value) {
|
||||
return EnsoContext.get(this).getBuiltins().function();
|
||||
}
|
||||
|
||||
@Specialization
|
||||
Object doDouble(double value) {
|
||||
return EnsoContext.get(this).getBuiltins().number().getDecimal();
|
||||
|
@ -301,4 +301,9 @@ spec = Test.group "Pattern Matches" <|
|
||||
_ : Any -> Nothing
|
||||
_ -> Test.fail "Expected to match on Any."
|
||||
|
||||
Test.specify "should allow for pattern matching on unresolved symbol" <|
|
||||
case (.name) of
|
||||
_ : Function -> Nothing
|
||||
_ -> Test.fail "Expected to match on Function type."
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -1,4 +1,5 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Function import Function
|
||||
import Standard.Base.Errors.File_Error.File_Error
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
from Standard.Base.Errors.Common import Uninitialized_State
|
||||
@ -358,5 +359,10 @@ spec =
|
||||
case atom.bar of
|
||||
n : Number -> Test.fail "Not changed to number: "+n
|
||||
_ -> Nothing
|
||||
|
||||
Test.group "Unresolved symbol"
|
||||
Test.specify "should be treated as a Function" <|
|
||||
(_.is_nothing) . is_a Function . should_equal True
|
||||
(.is_nothing) . is_a Function . should_equal True
|
||||
Meta.type_of (_.is_nothing) . should_equal Function
|
||||
Meta.type_of (.is_nothing) . should_equal Function
|
||||
main = Test_Suite.run_main spec
|
||||
|
Loading…
Reference in New Issue
Block a user