Skip to content

Commit

Permalink
Refactor cmd flag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Feb 9, 2024
1 parent 82b27e0 commit f0433ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
25 changes: 7 additions & 18 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export interface Config {
/**
* Perform type checking, so that values can be assigned to the corresponding definitions
*/
typeCheck: boolean
/**
* Perform semantic checking on every source file. If `false`, only definitions required by the main file will be
* checked
Expand All @@ -11,25 +7,18 @@ export interface Config {
}

export const defaultConfig = (): Config => ({
typeCheck: true,
libCheck: false
})

export const fromCmdFlags = (args: string[]): Config => {
const config = defaultConfig()
const typeCheckCmd = args
.find(a => a.startsWith('--typeCheck='))
?.split('=')
.at(-1)
if (typeCheckCmd) {
config.typeCheck = typeCheckCmd === 'true'
}
const libCheckCmd = args
.find(a => a.startsWith('--libCheck='))
config.libCheck = parseCmdFlag('libCheck', args) === 'true'
return config
}

export const parseCmdFlag = (name: string, args: string[]): string | undefined => {
return args
.find(a => a.startsWith(`${name}=`))
?.split('=')
.at(-1)
if (libCheckCmd) {
config.libCheck = libCheckCmd === 'true'
}
return config
}
2 changes: 0 additions & 2 deletions src/typecheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ export const genericToVirtual = (generic: Generic, ctx: Context): VirtualGeneric
}

export const isAssignable = (t: VirtualType, target: VirtualType, ctx: Context): boolean => {
if (!ctx.config.typeCheck) return true

if (t.kind === 'unknown-type' || target.kind === 'unknown-type') return true
if (t.kind === 'hole-type' || target.kind === 'hole-type') return true
if (t.kind === 'vid-type' && vidToString(t.identifier) === 'std::never::Never') return true
Expand Down

0 comments on commit f0433ae

Please sign in to comment.