wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function process(x:string){{return x;}} process(55);
function process(x:string){{return x;}} process('world');
Pass correct type.
TypeScript
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
for data in range(58) print(data)
for data in range(58): print(data)
Colon after for.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let temp = 65;
let temp = 65;
Correct.
JavaScript
arr[88]
if (arr.indices.contains(88)) arr[88]
Check index.
Kotlin
fn bar() -> i32 {{ 33 }}
fn bar() -> i32 {{ 33 }}
Correct.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(2);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(2, () => console.log('listening'));
Add callback.
Node.js
cin >> z;
int z; cin >> z;
Declare variable.
C++
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
List(63,4,97)
List(63,4,97)
Correct.
Scala
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
val z = 'value'
val z = "value"
Double quotes.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
my @arr = (21,80,57);
my @arr = (21,80,57);
Correct.
Perl
x := 44
x := 44
Correct.
Go
let y: number = 'test';
let y: string = 'test';
Fix type.
TypeScript
int x = 'world';
String x = 'world';
Type mismatch.
Dart
if a = 15
if a == 15
Use ==.
Ruby
// comment
/* comment */
Use /* */.
CSS
function test(): void {{ return 34; }}
function test(): number {{ return 34; }}
Return type mismatch.
TypeScript
[98, 5, 91
[98, 5, 91]
Close bracket.
Python
if bar = 69 then print('message') end
if bar == 69 then print('message') end
Use ==.
Lua
int list[41]; list[41]=5;
int list[41]; if(41<41){{}} else list[41]=5;
Bounds check.
C++
x := 60
x := 60
Correct.
Go
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
let data = 32;
let data = 32;
Correct.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
values[100]
if values.indices.contains(100) {{ values[100] }}
Check index.
Swift
const count = 88; count = 57;
let count = 88; count = 57;
Cannot reassign const.
JavaScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
print 'test'
print('test')
print needs parentheses.
Python
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:24}};
Add missing property.
TypeScript
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(59);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(59);
Correct.
Node.js
if x = 42
if x == 42
Use ==.
Go
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
switch(a){{ case 10: break; }}
switch(a){{ case 10: break; default: break; }}
Add default case.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[x*x for x in arr if x > 12]
[x*x for x in arr if x > 12]
Correct list comprehension.
Python
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
{{"title":"message" "name":90}}
{{"title":"message", "name":90}}
Add comma.
JSON
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
'data' + 48
'data' + 48.to_s
Convert int.
Ruby
if (b = 77)
if (b == 77)
Use ==.
R
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
let mut c=66; let r1=&mut c; let ref2=&mut c;
let mut c=66; {{ let r1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
'message' + 3
'message' + str(3)
Can't add int to string.
Python
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
var a int = 'world'
var a string = 'world'
Type mismatch.
Go
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
fn render() -> i32 {{ 24 }}
fn render() -> i32 {{ 24 }}
Correct.
Rust
assert b > 60
assert b > 60
Correct.
Python
String name = 'data';
String name = 'data';
Correct.
Dart
if ($b = 84)
if ($b == 84)
Use ==.
Perl
UPDATE orders SET id='data' WHERE role=58
UPDATE orders SET id='data' WHERE role=58;
Add semicolon.
SQL
name: message age: 46
name: message age: 46
Correct.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if ($index = 85) {{}}
if ($index -eq 85) {{}}
Use -eq.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (val = 71) {}
if (val == 71) {}
Use ==.
Dart
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
val z = 'result'
val z = "result"
Double quotes.
Kotlin
else print('value')
else: print('value')
Colon after else.
Python
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
["output", 88]
["output", 88]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print('output')
print('output')
Correct.
R
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if num = 68:
if num == 68:
Use == for comparison.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
$arr[45] = 5;
if (isset($arr[45])) $arr[45] = 5;
Check existence.
PHP
math.sqrt(80)
import math math.sqrt(80)
Import module first.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let s = String::from("data"); let ref=&s; s.push_str("!");
let mut s = String::from("data"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
String z = 'info';
String z = "info";
Double quotes.
Java
baz
baz()
Add parentheses.
Kotlin
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python