Skip to content

Commit

Permalink
type-bounds in not a valid type
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Jul 27, 2024
1 parent 5d681b8 commit 00fc2b8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion nois.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ identifier ::= (NAME COLON COLON)* NAME type-args?
;
type-args ::= O-ANGLE (type (COMMA type)* COMMA?)? C-ANGLE
;
type ::= type-bounds | fn-type | hole
type ::= identifier | fn-type | hole
;
type-bounds ::= identifier (PLUS identifier)*
;
Expand Down
3 changes: 1 addition & 2 deletions src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
buildStatement,
buildUseExpr
} from './statement'
import { FnType, Generic, Type, TypeBounds, buildType } from './type'
import { FnType, Generic, Type, buildType } from './type'
import { FieldDef, TypeDef, Variant } from './type-def'

export type AstNode =
Expand All @@ -69,7 +69,6 @@ export type AstNode =
| Arg
| Block
| Param
| TypeBounds
| FnType
| Generic
| IfExpr
Expand Down
11 changes: 3 additions & 8 deletions src/ast/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import { Checked } from '../semantic'
import { Hole, buildHole } from './match'
import { Identifier, Name, buildIdentifier, buildName } from './operand'

export type Type = (Identifier | TypeBounds | FnType | Hole) & Partial<Checked>
export type Type = (Identifier | FnType | Hole) & Partial<Checked>

export const buildType = (node: ParseNode, ctx: Context): Type => {
const n = filterNonAstNodes(node)[0]
if (node.kind === 'type-annot') {
return buildType(n, ctx)
} else if (n.kind === 'type-bounds') {
const typeBounds = buildTypeBounds(n, ctx)
if (typeBounds.bounds.length === 1) {
return typeBounds.bounds[0]
} else {
return typeBounds
}
} else if (n.kind === 'identifier') {
return buildIdentifier(n, ctx)
} else if (n.kind === 'hole') {
return buildHole(n)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/parser/fns/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export const parseTypeAnnot = (parser: Parser): void => {
}

/**
* type ::= type-bounds | fn-type | hole
* type ::= identifier | fn-type | hole
*/
export const parseType = (parser: Parser): void => {
const mark = parser.open()
if (parser.atAny(nameLikeTokens)) {
parseTypeBounds(parser)
parseIdentifier(parser)
} else if (parser.atAny(['pipe', 'o-angle'])) {
parseFnType(parser)
} else if (parser.at('underscore')) {
Expand Down
4 changes: 0 additions & 4 deletions src/phase/name-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export const resolveName = (node: AstNode, ctx: Context): void => {
}
break
}
case 'type-bounds': {
node.bounds.forEach(b => resolveName(b, ctx))
break
}
case 'fn-type': {
resolveName(node.returnType, ctx)
node.paramTypes.forEach(pt => resolveName(pt, ctx))
Expand Down

0 comments on commit 00fc2b8

Please sign in to comment.