Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libraries/Microsoft.PowerFx.Core/Public/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public Engine(PowerFxConfig powerFxConfig)
public ReadOnlySymbolTable SupportedFunctions { get; protected internal set; } = _allBuiltinCoreFunctions;

/// <summary>
/// Builtin Types supported by this engine.
/// Builtin Types supported by this engine for UDFs and UDTs.
/// </summary>
public ReadOnlySymbolTable PrimitiveTypes { get; protected internal set; } = ReadOnlySymbolTable.PrimitiveTypesTableInstance;
public ReadOnlySymbolTable PrimitiveTypes { get; protected internal set; }

// By default, we pull the core functions.
// These can be overridden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

using System.Text;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class BooleanType : FormulaType
{
public override DName Name => new DName("Boolean");

internal BooleanType()
: base(DType.Boolean)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
using System;
using System.Text;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class ColorType : FormulaType
{
public override DName Name => new DName("Color");

internal ColorType()
: base(DType.Color)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

using System.Diagnostics;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
[DebuggerDisplay("{_type}:tzi")]
public class DateTimeNoTimeZoneType : FormulaType
{
public override DName Name => new DName("DateTimeTZInd");

internal DateTimeNoTimeZoneType()
: base(DType.DateTimeNoTimeZone)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.PowerFx.Types
{
public class DateTimeType : FormulaType
{
public override DName Name => new DName("DateTime");

internal DateTimeType()
: base(DType.DateTime)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Microsoft.PowerFx.Types
{
public class DateType : FormulaType
{
public override DName Name => new DName("Date");

internal DateType()
: base(DType.Date)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Licensed under the MIT license.

using System.Text;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class DecimalType : FormulaType
{
{
public override DName Name => new DName("Decimal");

internal DecimalType()
: base(DType.Decimal)
{
Expand Down
32 changes: 17 additions & 15 deletions src/libraries/Microsoft.PowerFx.Core/Public/Types/FormulaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public abstract class FormulaType
#pragma warning disable SA1300 // Element should begin with upper-case letter
// Uses init to allow setting from derived constructors. Otherwise, is immutable.
internal DType _type { get; private protected init; }
#pragma warning restore SA1300 // Element should begin with upper-case letter
#pragma warning restore SA1300 // Element should begin with upper-case letter

public virtual DName Name { get; }

public static FormulaType Blank { get; } = new BlankType();

Expand Down Expand Up @@ -76,20 +78,20 @@ internal FormulaType(DType type)

internal static readonly IReadOnlyDictionary<DName, FormulaType> PrimitiveTypes = ImmutableDictionary.CreateRange(new Dictionary<DName, FormulaType>()
{
{ new DName("Boolean"), Boolean },
{ new DName("Color"), Color },
{ new DName("Date"), Date },
{ new DName("Time"), Time },
{ new DName("DateTime"), DateTime },
{ new DName("DateTimeTZInd"), DateTimeNoTimeZone },
{ new DName("GUID"), Guid },
{ new DName("Number"), Number },
{ new DName("Decimal"), Decimal },
{ new DName("Text"), String },
{ new DName("Hyperlink"), Hyperlink },
{ new DName("None"), Blank },
{ new DName("Dynamic"), UntypedObject },
{ new DName("Void"), Void },
{ Boolean.Name, Boolean },
{ Color.Name, Color },
{ Date.Name, Date },
{ Time.Name, Time },
{ DateTime.Name, DateTime },
{ DateTimeNoTimeZone.Name, DateTimeNoTimeZone },
{ Guid.Name, Guid },
{ Number.Name, Number },
{ Decimal.Name, Decimal },
{ String.Name, String },
{ Hyperlink.Name, Hyperlink },
{ Blank.Name, Blank },
{ UntypedObject.Name, UntypedObject },
{ Void.Name, Void },
});

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Microsoft.PowerFx.Types
{
public class GuidType : FormulaType
{
public override DName Name => new DName("GUID");

internal GuidType()
: base(DType.Guid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

using System;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class HyperlinkType : FormulaType
{
public override DName Name => new DName("Hyperlink");

internal HyperlinkType()
: base(DType.Hyperlink)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

using System.Text;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class NumberType : FormulaType
{
public override DName Name => new DName("Number");

internal NumberType()
: base(DType.Number)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Microsoft.PowerFx.Types
{
public class StringType : FormulaType
{
public override DName Name => new DName("Text");

public StringType()
: base(DType.String)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
using System;
using System.Text;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class TimeType : FormulaType
{
public override DName Name => new DName("Time");

internal TimeType()
: base(DType.Time)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;

namespace Microsoft.PowerFx.Types
{
public class UntypedObjectType : FormulaType
{
public override DName Name => new DName("Dynamic");

public UntypedObjectType()
: base(DType.UntypedObject)
{
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/Public/Types/Void.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;
using Microsoft.PowerFx.Types;

namespace Microsoft.PowerFx.Types
Expand All @@ -11,6 +12,8 @@ namespace Microsoft.PowerFx.Types
/// </summary>
public sealed class Void : FormulaType
{
public override DName Name => new DName("Void");

internal Void()
: base(DType.Void)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class UserDefinitions
/// <summary>
/// Restricted return type.
/// </summary>
public static readonly ISet<DType> RestrictedTypes = ImmutableHashSet.Create(DType.DateTimeNoTimeZone, DType.ObjNull, DType.Decimal);
public static readonly ISet<DType> RestrictedTypes = ImmutableHashSet.Create(DType.ObjNull);

/// <summary>
/// REstricted parameter type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public override bool HasSuggestionsForParam(int argIndex)
return argIndex == 1;
}

// This list is intersected with Engine.PrimitiveTypes, with outliers generating errors before this list is checked.
// In other words, just because a type is listed here, does not mean it is supported unless it is also in Engine.PrimitiveTypes.
// Notably this list excludes ObjNull and Void, which make no sense to use in JSON or UDFs (except for UDF return type for Void).
// It also excludes Color, as we have not implemented the coversion of "Red" and other color names. We could convert # hex colors but this has not been done.
internal static readonly ISet<DType> SupportedJSONTypes = new HashSet<DType> { DType.Boolean, DType.Number, DType.Decimal, DType.Date, DType.DateTime, DType.DateTimeNoTimeZone, DType.Time, DType.String, DType.Guid, DType.Hyperlink, DType.UntypedObject };

public UntypedOrJSONConversionFunction(string name, TexlStrings.StringGetter description, DType returnType, int arityMax, params DType[] paramTypes)
Expand Down
20 changes: 20 additions & 0 deletions src/libraries/Microsoft.PowerFx.Interpreter/RecalcEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -43,6 +44,23 @@ public RecalcEngine()
{
}

internal static readonly ReadOnlySymbolTable _recalcPrimitiveTypes =
SymbolTable.NewDefaultTypes(ImmutableDictionary.CreateRange(new Dictionary<DName, FormulaType>()
{
{ FormulaType.Boolean.Name, FormulaType.Boolean },
{ FormulaType.Color.Name, FormulaType.Color },
{ FormulaType.Date.Name, FormulaType.Date },
{ FormulaType.Time.Name, FormulaType.Time },
{ FormulaType.DateTime.Name, FormulaType.DateTime },
{ FormulaType.Guid.Name, FormulaType.Guid },
{ FormulaType.Number.Name, FormulaType.Number },
{ FormulaType.Decimal.Name, FormulaType.Decimal },
{ FormulaType.String.Name, FormulaType.String }, // Text
{ FormulaType.Hyperlink.Name, FormulaType.Hyperlink },
{ FormulaType.UntypedObject.Name, FormulaType.UntypedObject }, // Dynamic
{ FormulaType.Void.Name, FormulaType.Void },
}));

public RecalcEngine(PowerFxConfig powerFxConfig)
: base(powerFxConfig)
{
Expand All @@ -52,6 +70,8 @@ public RecalcEngine(PowerFxConfig powerFxConfig)

base.EngineSymbols = _symbolTable;

base.PrimitiveTypes = _recalcPrimitiveTypes;

// Add Builtin functions that aren't yet in the shared library.
SupportedFunctions = _interpreterSupportedFunctions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ true
false

>> AsType(ParseJSON("""1900-12-31T00:00:00.000Z"""), DateTimeTZInd)
DateTime(1900,12,31,0,0,0,0)
Errors: Error 50-63: Name isn't valid. 'DateTimeTZInd' isn't recognized.|Error 0-64: Invalid argument 'DateTimeTZInd'. Expected valid type name or inline type expression.

>> AsType(ParseJSON("""1900-12-31T00:00:00.000-08:00"""), DateTimeTZInd)
DateTime(1900,12,31,8,0,0,0)
Errors: Error 55-68: Name isn't valid. 'DateTimeTZInd' isn't recognized.|Error 0-69: Invalid argument 'DateTimeTZInd'. Expected valid type name or inline type expression.

>> Value(AsType(ParseJSON("42"), Dynamic))
42
Expand Down Expand Up @@ -119,10 +119,10 @@ Errors: Error 26-30: Unsupported type 'Void' in type argument.
Errors: Error 0-59: Invalid number of arguments: received 3, expected 2.

>> AsType(ParseJSON("true"), None)
Errors: Error 26-30: Unsupported type 'Blank' in type argument.
Errors: Error 26-30: Name isn't valid. 'None' isn't recognized.|Error 0-31: Invalid argument 'None'. Expected valid type name or inline type expression.

>> AsType(ParseJSON("null"), None)
Errors: Error 26-30: Unsupported type 'Blank' in type argument.
Errors: Error 26-30: Name isn't valid. 'None' isn't recognized.|Error 0-31: Invalid argument 'None'. Expected valid type name or inline type expression.

>> AsType(ParseJSON("{}"), Type({a: Text, b: [Color]}))
Errors: Error 28-29: Unsupported type 'Color' in type argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ true
true

>> IsType(ParseJSON("""1900-12-31T00:00:00.000Z"""), DateTimeTZInd)
true
Errors: Error 50-63: Name isn't valid. 'DateTimeTZInd' isn't recognized.|Error 0-64: Invalid argument 'DateTimeTZInd'. Expected valid type name or inline type expression.

>> IsType(ParseJSON("""true"""), Boolean)
false
Expand Down Expand Up @@ -111,7 +111,7 @@ Errors: Error 26-30: Unsupported type 'Void' in type argument.
Errors: Error 0-59: Invalid number of arguments: received 3, expected 2.

>> IsType(ParseJSON("true"), None)
Errors: Error 26-30: Unsupported type 'Blank' in type argument.
Errors: Error 26-30: Name isn't valid. 'None' isn't recognized.|Error 0-31: Invalid argument 'None'. Expected valid type name or inline type expression.

>> IsType(ParseJSON("{}"), Type({a: Text, b: [Color]}))
Errors: Error 28-29: Unsupported type 'Color' in type argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ true
false

>> ParseJSON("""1900-12-31T00:00:00.000Z""", DateTimeTZInd)
DateTime(1900,12,31,0,0,0,0)
Errors: Error 42-55: Name isn't valid. 'DateTimeTZInd' isn't recognized.|Error 0-56: Invalid argument 'DateTimeTZInd'. Expected valid type name or inline type expression.

>> ParseJSON("""1900-12-31T00:00:00.000-08:00""", DateTimeTZInd)
DateTime(1900,12,31,8,0,0,0)
Errors: Error 47-60: Name isn't valid. 'DateTimeTZInd' isn't recognized.|Error 0-61: Invalid argument 'DateTimeTZInd'. Expected valid type name or inline type expression.

>> Value(ParseJSON("42", Dynamic))
42
Expand Down Expand Up @@ -128,10 +128,10 @@ Errors: Error 18-22: Unsupported type 'Void' in type argument.
Errors: Error 0-51: Invalid number of arguments: received 3, expected 2.

>> ParseJSON("true", None)
Errors: Error 18-22: Unsupported type 'Blank' in type argument.
Errors: Error 18-22: Name isn't valid. 'None' isn't recognized.|Error 0-23: Invalid argument 'None'. Expected valid type name or inline type expression.

>> ParseJSON("null", None)
Errors: Error 18-22: Unsupported type 'Blank' in type argument.
Errors: Error 18-22: Name isn't valid. 'None' isn't recognized.|Error 0-23: Invalid argument 'None'. Expected valid type name or inline type expression.

>> ParseJSON("{}", Type({a: Text, b: [Color]}))
Errors: Error 20-21: Unsupported type 'Color' in type argument.
Expand Down
Loading
Loading