From 94272bff03618a9970a11ffd78f946bf89d29d05 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 11 Apr 2024 23:22:27 -0400 Subject: [PATCH] Pass some tests --- analyzer/constant_test.go | 34 +++++++++++++++++----------------- analyzer/expression.go | 11 +++++++++-- analyzer/name_test.go | 2 +- analyzer/type.go | 3 +-- entity/literal.go | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/analyzer/constant_test.go b/analyzer/constant_test.go index d5d8392..c6c5db5 100644 --- a/analyzer/constant_test.go +++ b/analyzer/constant_test.go @@ -16,14 +16,14 @@ Weekday: Int [print s:String] [printWeekday w:Weekday] = [print switch w - | sunday 'sunday' - | monday 'monday' - | tuesday 'tuesday' - | wednesday 'wednesday' - | thursday 'thursday' - | friday 'friday' - | saturday 'saturday' - * 'unknown'] + | Weekday.sunday 'sunday' + | Weekday.monday 'monday' + | Weekday.tuesday 'tuesday' + | Weekday.wednesday 'wednesday' + | Weekday.thursday 'thursday' + | Weekday.friday 'friday' + | Weekday.saturday 'saturday' + * 'unknown'] [f] = [printWeekday Weekday.monday] `)} @@ -41,14 +41,14 @@ Weekday: Int [print s:String] [printWeekday w:Weekday] = [print switch w - | sunday 'sunday' - | monday 'monday' - | tuesday 'tuesday' - | wednesday 'wednesday' - | thursday 'thursday' - | friday 'friday' - | saturday 'saturday' - * 'unknown'] + | Weekday.sunday 'sunday' + | Weekday.monday 'monday' + | Weekday.tuesday 'tuesday' + | Weekday.wednesday 'wednesday' + | Weekday.thursday 'thursday' + | Weekday.friday 'friday' + | Weekday.saturday 'saturday' + * 'unknown'] [f] = [printWeekday Weekday.monday] `)} @@ -73,7 +73,7 @@ Weekday: String // name? func TestErrConstantStringUnspecified (test *testing.T) { testStringErr (test, -"cannot fill in constant values for non-numeric type Weekday", 5, 11, +"cannot fill in constant value for non-numeric type Weekday", 3, 1, ` Weekday: String | sunday diff --git a/analyzer/expression.go b/analyzer/expression.go index f09b052..00eb7eb 100644 --- a/analyzer/expression.go +++ b/analyzer/expression.go @@ -50,7 +50,14 @@ func (this *Tree) analyzeConstant ( }, false) // TODO perhaps we should accept incomplete ones? if err != nil { return nil, err } constant.Unit = typedef.Unit() - constant.Ty = into + constant.Ty = &entity.TypeNamed { + Pos: constant.Position(), + UnitNickname: constant.UnitNickname, + Name: typedef.Name, + Type: typedef.Type, + Acc: typedef.Access(), + Unt: typedef.Unit(), + } // check access permissions if typedef.Acc == entity.AccessPrivate && typedef.Unit() != this.unit { @@ -68,7 +75,7 @@ func (this *Tree) analyzeConstant ( } constant.Declaration = declaration - err = this.canAssign(constant.Position(), into, mode, declaration.Type()) + err = this.canAssign(constant.Position(), into, mode, constant.Type()) if err != nil { return nil, err } return constant, nil diff --git a/analyzer/name_test.go b/analyzer/name_test.go index f0c0711..086bd13 100644 --- a/analyzer/name_test.go +++ b/analyzer/name_test.go @@ -224,7 +224,7 @@ Weekday: String func TestConstantUniqueErr (test *testing.T) { testStringErr (test, -"Weekday.tuesday already defined at stream0.fspl:5:1", 8, 1, +"tuesday already defined at stream0.fspl:5:1", 8, 1, ` Weekday: String | sunday 'sunday' diff --git a/analyzer/type.go b/analyzer/type.go index d873c2a..8383b37 100644 --- a/analyzer/type.go +++ b/analyzer/type.go @@ -105,10 +105,9 @@ func (this *Tree) analyzeConstantDeclaration ( if err != nil { return nil, err } } - // TODO after analysis, check if constant return constant, nil } - + func (this *Tree) analyzeType ( ty entity.Type, acceptIncomplete bool, diff --git a/entity/literal.go b/entity/literal.go index d612fd1..a53d153 100644 --- a/entity/literal.go +++ b/entity/literal.go @@ -80,7 +80,7 @@ func (*LiteralString) expression(){} func (this *LiteralString) Position () errors.Position { return this.Pos } func (this *LiteralString) Type () Type { return this.Ty } func (this *LiteralString) HasExplicitType () bool { return false } -func (this *LiteralString) Description () string { return "sring literal" } +func (this *LiteralString) Description () string { return "string literal" } func (this *LiteralString) IsConstant () bool { return true } func (this *LiteralString) String () string { return Quote(this.ValueUTF8)