Pass some tests

This commit is contained in:
Sasha Koshka 2024-04-11 23:22:27 -04:00
parent 6ba8b5465b
commit 94272bff03
5 changed files with 29 additions and 23 deletions

View File

@ -16,14 +16,14 @@ Weekday: Int
[print s:String] [print s:String]
[printWeekday w:Weekday] = [print switch w [printWeekday w:Weekday] = [print switch w
| sunday 'sunday' | Weekday.sunday 'sunday'
| monday 'monday' | Weekday.monday 'monday'
| tuesday 'tuesday' | Weekday.tuesday 'tuesday'
| wednesday 'wednesday' | Weekday.wednesday 'wednesday'
| thursday 'thursday' | Weekday.thursday 'thursday'
| friday 'friday' | Weekday.friday 'friday'
| saturday 'saturday' | Weekday.saturday 'saturday'
* 'unknown'] * 'unknown']
[f] = [printWeekday Weekday.monday] [f] = [printWeekday Weekday.monday]
`)} `)}
@ -41,14 +41,14 @@ Weekday: Int
[print s:String] [print s:String]
[printWeekday w:Weekday] = [print switch w [printWeekday w:Weekday] = [print switch w
| sunday 'sunday' | Weekday.sunday 'sunday'
| monday 'monday' | Weekday.monday 'monday'
| tuesday 'tuesday' | Weekday.tuesday 'tuesday'
| wednesday 'wednesday' | Weekday.wednesday 'wednesday'
| thursday 'thursday' | Weekday.thursday 'thursday'
| friday 'friday' | Weekday.friday 'friday'
| saturday 'saturday' | Weekday.saturday 'saturday'
* 'unknown'] * 'unknown']
[f] = [printWeekday Weekday.monday] [f] = [printWeekday Weekday.monday]
`)} `)}
@ -73,7 +73,7 @@ Weekday: String
// name? // name?
func TestErrConstantStringUnspecified (test *testing.T) { func TestErrConstantStringUnspecified (test *testing.T) {
testStringErr (test, 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 Weekday: String
| sunday | sunday

View File

@ -50,7 +50,14 @@ func (this *Tree) analyzeConstant (
}, false) // TODO perhaps we should accept incomplete ones? }, false) // TODO perhaps we should accept incomplete ones?
if err != nil { return nil, err } if err != nil { return nil, err }
constant.Unit = typedef.Unit() 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 // check access permissions
if typedef.Acc == entity.AccessPrivate && typedef.Unit() != this.unit { if typedef.Acc == entity.AccessPrivate && typedef.Unit() != this.unit {
@ -68,7 +75,7 @@ func (this *Tree) analyzeConstant (
} }
constant.Declaration = declaration 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 } if err != nil { return nil, err }
return constant, nil return constant, nil

View File

@ -224,7 +224,7 @@ Weekday: String
func TestConstantUniqueErr (test *testing.T) { func TestConstantUniqueErr (test *testing.T) {
testStringErr (test, 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 Weekday: String
| sunday 'sunday' | sunday 'sunday'

View File

@ -105,10 +105,9 @@ func (this *Tree) analyzeConstantDeclaration (
if err != nil { return nil, err } if err != nil { return nil, err }
} }
// TODO after analysis, check if constant
return constant, nil return constant, nil
} }
func (this *Tree) analyzeType ( func (this *Tree) analyzeType (
ty entity.Type, ty entity.Type,
acceptIncomplete bool, acceptIncomplete bool,

View File

@ -80,7 +80,7 @@ func (*LiteralString) expression(){}
func (this *LiteralString) Position () errors.Position { return this.Pos } func (this *LiteralString) Position () errors.Position { return this.Pos }
func (this *LiteralString) Type () Type { return this.Ty } func (this *LiteralString) Type () Type { return this.Ty }
func (this *LiteralString) HasExplicitType () bool { return false } 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) IsConstant () bool { return true }
func (this *LiteralString) String () string { func (this *LiteralString) String () string {
return Quote(this.ValueUTF8) return Quote(this.ValueUTF8)