From 4a14564bff0074c97835fb86ca0ba043282a7f6a Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 14 Mar 2024 18:35:26 +0100 Subject: [PATCH] Fixed asType for string and non-string case --- .../lang/rascalcore/check/CollectPattern.rsc | 12 ++++++---- .../lang/rascalcore/compile/Examples/Tst5.rsc | 22 ------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectPattern.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectPattern.rsc index 32efe165..7bef0031 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectPattern.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/check/CollectPattern.rsc @@ -342,11 +342,15 @@ void collect(current: (Pattern) `type ( , // ---- asType void collect(current: (Pattern) `[ ] `, Collector c){ c.fact(current, tp); - // TODO: explore why this gives undesired erors, e..g in lang::rascal::grammar::definition::Literals - //c.requireSubType(p, tp, error(p, "Pattern should be subtype of %t, found %t", tp, p)); - // TODO: missing semantics [Type] where pattern is of a string type. The str will be parsed with the non-terminal. - // if it is another type, then it must be comparable and the [Type] is used to see if a downcast is possible using isSubTypeOf + // If pattern is of type string, the string will be parsed using the non-terminal tp. + // If the pattern has another type, then it must be a subtype of tp + + c.require("asType", current, [tp, p], void(Solver s){ + if(!isStrAType(s.getType(p))){ + s.requireSubType(p, tp, error(p, "Pattern should be subtype of %t, found %t", tp, p)); + } + }); collect(tp, c); c.push(patternContainer, "asType"); collect(p, c); diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc index 5ac54ee7..e32c2466 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc @@ -1,27 +1,5 @@ module lang::rascalcore::compile::Examples::Tst5 - -syntax Expr = "e"; - -syntax Expr = - right - ( right postIncr: Expr "++" - | right postDecr: Expr "--" - ) - > left - ( left div: Expr "/" !>> [/] Expr - | left remain: Expr "%" Expr - ) - ; - -syntax Expr = - castPrim: "(" "PrimType" ")" Expr - > left - ( left div: Expr "/" !>> [/] Expr - | left remain: Expr "%" Expr - ) - ; - //import List; //