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]
[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

View File

@ -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

View File

@ -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'

View File

@ -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,

View File

@ -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)